Harry Pell scored a late winner to haul Wimbledon out of the relegation zone and condemn Nigel Worthington to a losing start as York City boss.
Mat Mitchel-King's half-volley put the Dons in front, but Chris Smith levelled before the break with a header.
Brennan Dickenson took the ball past keeper Michael Ingham to restore the home side's lead, only for Smith to bundle in another equaliser.
But Pell finished off a post to lift Wimbledon from bottom to 21st.
The former Hereford United midfielder's 79th-minute strike, the January deadline signing's second goal in three games, lifts the Dons to within a point of the Minstermen in 19th place.
VIEW FROM THE DRESSING ROOM
AFC Wimbledon boss Neil Ardley told BBC London 94.9:
"I said to the players 'Are you trying to make me go grey?'
"It was a dramatic win but I asked them to show character earlier this season and they showed bundles of it today.
"I felt the performance levels of the boys were excellent.
"We were the better team and that doesn't always work, but I was proud of them."
City manager Nigel Worthington told BBC Radio York:
"I thought the players' participation in that was outstanding. They kept going right until the final whistle, which showed a lot of character.
"But, if you score two goals away from home, you should be getting something from the game.
"There was a lot to deal with but we dealt with it and things we've been working on, a lot of them came off but there's one or two we've got to continue to work on.
"But, for their commitment and their energy, I can't fault the players at all."
AFC Wimbledon 22 Sullivan 05 Balkestein 06 Mitchell-King 31 Meades 39 Bennett 08 S Moore Booked 12 Pell Booked 23 Yussuff (Darco - 80' ) 09 Dickenson (Sainte-Luce - 67' ) 10 Midson 28 Alexander Substitutes 33 Jaimez-Ruiz 03 Cummings 07 Long 16 Sainte-Luce 11 L Moore 14 Darco 21 Strutton York City 24 Ingham 04 Smith 06 Parslow 16 Fyfield 22 O'Connell 08 Kerr 17 Blair (Rodman - 66' Booked ) 26 McLaughlin (Walker - 66' ) 29 McGrath 10 Chambers Booked 25 Rankine Substitutes 01 Jameson 23 Doig 12 Bullock 13 McDaid 19 Potts 33 Rodman 09 Walker