Striker Richard Brodie was the York hero as the Blue Square Premier side scored twice in the final five minutes to snatch a shock 3-2 win against League Two Crewe.
Brodie scored York's third in the 88th minute just minutes after Richard Pacquette had equalised for Martin Foyle's men.
Crewe had been cruising into the second round as goals from Joel Grant and Calvin Zola had sandwiched Brodie's first effort - but there was late drama as the Alex slipped out.
Zola could have got Crewe off to a perfect start, but with time and space he blazed over from eight yards.
But the Railwaymen broke the deadlock in the 33rd minute after good work from Byron Moore found Grant inside the area and he fired into the roof of the net.
York hit back six minutes before the break when Brodie's header from eight yards left goalkeeper Steve Phillips with no chance.
The scores remained level for just two minutes, Grant this time turning provider to pick out Zola for his 13th goal of the season - a header from 12 yards.
The home side continued to push forward after the break, and following a succession of corners, Pacquette stabbed in the equaliser following Craig Nelthorpe's flag-kick.
Brodie lit up Bootham Crescent shortly afterwards with a neat 18-yard strike to send City into the second round.