Tuffy Gosewisch doubled off Zac Rosscup (1-1) with one out in the 13th, then Ahmed - who earlier hit his second career home run - lined one sharply into the left-field corner to give the Diamondbacks their fifth straight victory.
Randall Delgado (2-2), the last of all eight relievers used by Arizona, escaped a bases-loaded jam in the 13th for the victory.
Kris Bryant and Starlin Castro each singled in a run to put the Cubs up 4-2 in the 10th.
Copyright 2015 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.