Scottish Premier League new boys Dunfermline struggled to overcome Third Division Annan before progressing to the second round of the League Cup.
Dunfermline striker Andy Barrowman rose above the defence to powerfully steer it into the net with his head after 17 minutes.
But David Cox fired the equaliser after a mazy run four minutes later.
Annan's Ian Harty had an overhead kick cleared off the line by Andy Kirk, who headed the winner after 51 minutes.
It was Annan that had the first scoring chance of the match after three minutes, when Sean O'Connor's close-range shot from six yards was blocked by goalkeeper Paul Gallagher.
Kirk nearly scored a stunning goal when his shot from 18 yards struck the crossbar and went over.
O'Connor again went close for Annan, while Paul Burns' powerful shot from six yards was pushed round the post by Annan goalkeeper Craig Summersgill.
Dunfermline's pressure paid off when Burns played the ball in from a corner on the right-hand side and Barrowman rose above the defence to powerfully steer it into the net with his head.
However, Cox picked up the ball just in front of the 18-yard box, twisted and turned before firing the ball into the back of the net.
Annan could have gone ahead in spectacular style in the 32nd minute when Harty's overhead scissors kick blocked by Kirk on the goal line.
Dunfermline came out determined after the break and Kirk headed in from close range from a Joe Cardle cross.
The Pars had the ball in the net in the 70th minute, but Barrowman was judged to be offside in the six-yard box.
Annan should have taken advantage of an excellent cross in the 85th minute from Cox that was played into the box from the left-hand side with no-one waiting in an empty box to pick it up.