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."
Live Text Commentary
Full Time The match has reached full-time.90:00 +4:02 Booking
Booking Booking for Sammy Moore for dissent.90:00 +3:41
Free kick awarded for an unfair challenge on Jamal Fyfield by Gary Alexander. Direct free kick taken by Michael Ingham.87:56
Michael Rankine gives away a free kick for an unfair challenge on Jack Midson. Direct free kick taken by John Sullivan.87:34
Mat Mitchel-King challenges Jamal Fyfield unfairly and gives away a free kick. Direct free kick taken by Michael Ingham.86:50
Foul by Alex Rodman on Harry Pell, free kick awarded. Sammy Moore takes the free kick.85:45
The assistant referee signals for offside against Gary Alexander. Free kick taken by Michael Ingham.85:04
John Sullivan restarts play with the free kick.84:49 Booking
Booking Alex Rodman goes into the referee's book.83:53
John Sullivan restarts play with the free kick.83:53 Booking
Booking Ashley Chambers is booked.83:20
Free kick awarded for an unfair challenge on Kevin Sainte-Luce by Ashley Chambers.79:51
Jason Walker takes a shot. Comfortable save by John Sullivan.79:28 Substitution
Substitution Jessie Darko is brought on as a substitute for Rashid Yussuff.78:33 Goal scored
Goal! - Harry Pell - Wimbledon 3 - 2 York Harry Pell grabs a goal from just outside the penalty area to the bottom left corner of the goal. AFC Wimbledon 3-2 York.77:49
Outswinging corner taken from the right by-line by Sammy Moore, Jamal Fyfield makes a clearance.75:32
Unfair challenge on Chris Smith by Pim Balkestein results in a free kick. Direct free kick taken by Michael Ingham.75:02
Jack Midson fouled by John McGrath, the ref awards a free kick. Rashid Yussuff takes the free kick.73:03
Foul by Michael Rankine on Jon Meades, free kick awarded. Direct free kick taken by Sammy Moore.71:25
The assist for the goal came from John McGrath.
Goal! - Chris Smith - Wimbledon 2 - 2 York Chris Smith grabs a headed goal from close in. AFC Wimbledon 2-2 York.70:37
Jon Meades gives away a free kick for an unfair challenge on Jason Walker. John McGrath crosses the ball,69:40
The assistant referee flags for offside against Gary Alexander. Indirect free kick taken by Michael Ingham.68:40
Free kick taken by Jamal Fyfield.68:40 Booking
Booking The referee cautions Harry Pell for unsporting behaviour.68:17
Foul by Harry Pell on Ashley Chambers, free kick awarded.65:29 Substitution
Substitution Kevin Sainte-Luce joins the action as a substitute, replacing Brennan Dickenson.65:29 Substitution
Substitution Jason Walker comes on in place of Patrick McLaughlin.65:29 Substitution
Substitution Alex Rodman replaces Matty Blair.63:08
Corner from the right by-line taken by Sammy Moore, Daniel Parslow manages to make a clearance.62:35
Unfair challenge on Sammy Moore by Scott Kerr results in a free kick. John Sullivan takes the free kick.59:58
The assist for the goal came from Jack Midson.59:58 Goal scored
Goal! - Brennan Dickenson - Wimbledon 2 - 1 York Brennan Dickenson scores a goal from close range low into the middle of the goal. AFC Wimbledon 2-1 York.56:14
Alan Bennett takes a shot. Michael Ingham makes a comfortable save.55:38
Chris Smith concedes a free kick for a foul on Jack Midson. Free kick taken by Sammy Moore.54:12
Jack Midson takes a shot. Save by Michael Ingham.52:40
Jack O'Connell fouled by Jack Midson, the ref awards a free kick. Free kick taken by Jack O'Connell.51:43
Sammy Moore takes the inswinging corner, Shot from deep inside the area by Gary Alexander goes over the bar.51:00
Corner taken left-footed by Rashid Yussuff from the left by-line, Pim Balkestein takes a shot. Michael Ingham makes a save.46:45
Inswinging corner taken left-footed by John McGrath from the right by-line, Alan Bennett fouled by Michael Rankine, the ref awards a free kick. John Sullivan restarts play with the free kick.45:01
The second half kicks off.45:00 +3:02 Half time
Half Time The match has reached half-time.45:00 +2:08
Patrick McLaughlin is flagged offside by the assistant referee. Indirect free kick taken by John Sullivan.45:00 +0:45
Unfair challenge on Jon Meades by Patrick McLaughlin results in a free kick. Sammy Moore takes the direct free kick.45:00 +0:03
Inswinging corner taken by Sammy Moore, clearance by Chris Smith.43:25
Gary Alexander takes a shot.42:03
Foul by Jack Midson on Chris Smith, free kick awarded. Michael Ingham takes the free kick.39:20
Ashley Chambers takes a shot. Save by John Sullivan.39:07
Ashley Chambers takes a shot. Gary Alexander gets a block in.38:16
Corner taken left-footed by John McGrath, clearance by Pim Balkestein.35:54
Chris Smith concedes a free kick for a foul on Gary Alexander. Sammy Moore takes the free kick.34:10
Unfair challenge on Pim Balkestein by Michael Rankine results in a free kick. John Sullivan restarts play with the free kick.28:58
Assist by Ashley Chambers.28:58 Goal scored
Goal! - Chris Smith - Wimbledon 1 - 1 York Chris Smith finds the back of the net with a headed goal from inside the penalty area. AFC Wimbledon 1-1 York.27:36
Gary Alexander is flagged offside by the assistant referee. Jamal Fyfield takes the free kick.27:01
Effort on goal by Gary Alexander from inside the penalty box misses to the right of the target.26:13
Corner taken by Sammy Moore, Pim Balkestein takes a shot. Save by Michael Ingham.24:46
Corner taken right-footed by Sammy Moore from the left by-line, Gary Alexander takes a shot. Jack O'Connell gets a block in.23:07
Gary Alexander is penalised for a handball. Jamal Fyfield restarts play with the free kick.20:28
Harry Pell provided the assist for the goal.20:28 Goal scored
Goal! - Mat Mitchel-King - Wimbledon 1 - 0 York Mat Mitchel-King finds the net with a goal from the edge of the penalty box to the top right corner of the goal. AFC Wimbledon 1-0 York.14:26
Brennan Dickenson challenges Daniel Parslow unfairly and gives away a free kick. Michael Ingham takes the direct free kick.12:15
Brennan Dickenson takes a shot. Blocked by Daniel Parslow.8:59
Gary Alexander takes a shot. Save made by Michael Ingham.8:26
Free kick awarded for a foul by Patrick McLaughlin on Jon Meades. Sammy Moore restarts play with the free kick.7:25
Corner taken left-footed by Rashid Yussuff from the right by-line, Daniel Parslow makes a clearance.6:37
Inswinging corner taken left-footed by Rashid Yussuff from the right by-line, clearance by Michael Rankine.5:44
John McGrath fouled by Harry Pell, the ref awards a free kick. Jack O'Connell restarts play with the free kick.5:14
Effort from the edge of the box by Sammy Moore goes wide of the left-hand post.3:58
The referee gives a free kick against Gary Alexander for handball. Free kick taken by Michael Ingham.3:27
The assistant referee flags for offside against Matty Blair. Indirect free kick taken by John Sullivan.2:15
Effort on goal by Rashid Yussuff from deep inside the penalty area misses to the right of the target.0:33
Foul by Patrick McLaughlin on Mat Mitchel-King, free kick awarded. Sammy Moore takes the free kick.0:00
The ref blows the whistle to begin the match.
Live data and text provided by our data suppliers