Northampton's 10-match winning run at Sixfields was ended by struggling York, who moved three points clear of the drop zone.
Ashley Chambers fired in from 10 yards to put the Minstermen in front.
York keeper Michael Ingham made a string of saves before John Johnson turned Matty Blair's cross into his own net to make it 2-0.
It ended a winning streak that began on 22 December and dented the promotion hopes of Aidy Boothroyd's Cobblers.
Northampton are sixth in League Two, five points behind third-placed Burton, while one win from their remaining three games will guarantee a play-off place.
VIEW FROM THE DRESSING ROOM
Northampton Town manager Aidy Boothroyd tells BBC Radio Northampton:
"We got what we deserved. We didn't play the conditions particularly well in the first half and they scored at a key time.
"The expectation level goes right up. Some of the players try too hard.
"We made daft decisions defensively and offensively. The pressure was on us and we didn't deal with it very well today.
"We will do all we can to get automatic promotion and if not, we'll do our best to get out of this league. Simple as that. But today was a reality check."
York City manager Nigel Worthington told BBC Radio York:
"We knew we had to perform because Northampton's form at home has been exceptional throughout the season.
"We knew we had to certainly go and deal with them and then go and play when we got the opportunity and I though the players that were out there were outstanding.
"It was good that we carried out what we worked on and we deserved the result. Credit to the lads."
Live Text Commentary
Full Time The referee blows his whistle to end the game.90:00 +3:17
Jason Walker is penalised for handball and concedes a free kick. Direct free kick taken by Lee Nicholls.90:00 +0:36
The referee blows for offside against Ashley Chambers. Direct free kick taken by Lee Nicholls.87:31
Drilled left-footed shot by Ashley Chambers. Lee Nicholls makes a save.87:02 Substitution
Substitution Jake Robinson leaves the field to be replaced by David Moyo.84:56
The assist for the goal came from Matty Blair.84:56 Goal scored
Goal! - John Johnson - Northamp'n 0 - 2 York John Johnson scores an own goal. Northampton 0-2 York.84:56
The ball is swung over by Matty Blair,83:32
Effort on goal by Roy O'Donovan from 12 yards. Michael Ingham gets a block in. Ben Harding takes the inswinging corner, Headed effort from close range by Adebayo Akinfenwa goes wide left of the target.82:54
Matty Blair delivers the ball, Lee Collins manages to make a clearance. Centre by Matty Blair.82:33
Jake Robinson produces a cross, comfortable save by Michael Ingham.81:44
The ball is delivered by Luke Guttridge, Shot from 12 yards from Roy O'Donovan. Comfortable save by Michael Ingham.79:42
Jason Walker challenges Lee Collins unfairly and gives away a free kick. Lee Nicholls takes the free kick.77:44 Booking
Booking Clarke Carlisle receives a caution.77:33
Clarke Carlisle gives away a free kick for an unfair challenge on Matty Blair. Ashley Chambers restarts play with the free kick.76:39
Header from deep inside the area by Adebayo Akinfenwa goes over the bar.75:46 Substitution
Substitution Clive Platt replaces Joe Widdowson.72:58
Free kick awarded for an unfair challenge on Lee Collins by Adam Reed. Lee Nicholls restarts play with the free kick.71:15
Adebayo Akinfenwa concedes a free kick for a foul on Lanre Oyebanjo. Direct free kick taken by Michael Ingham.70:32
The ball is delivered by Roy O'Donovan, Effort from inside the area by Jake Robinson misses to the left of the goal.
Tom Platt takes a shot. Save by Lee Nicholls.67:06 Booking
Booking Lee Collins receives a yellow card for dissent.66:59
Lee Collins challenges Jason Walker unfairly and gives away a free kick. Michael Ingham takes the free kick.65:29
Free kick awarded for an unfair challenge on Lanre Oyebanjo by Jake Robinson. Direct free kick taken by Lanre Oyebanjo.64:42
Adebayo Akinfenwa concedes a free kick for a foul on Michael Ingham. Michael Ingham takes the direct free kick.62:14
Jason Walker is caught offside. Direct free kick taken by Lee Nicholls.62:14 Substitution
Substitution Luke Guttridge joins the action as a substitute, replacing Chris Hackett.61:08
The ball is swung over by Lanre Oyebanjo, Clarke Carlisle manages to make a clearance.60:04
Adebayo Akinfenwa handles the ball and concedes a free kick. Jack O'Connell restarts play with the free kick.55:16
Adebayo Akinfenwa takes a shot. Save by Michael Ingham. Inswinging corner taken from the left by-line by Chris Hackett.52:21
Chris Hackett delivers the ball from the free kick right-footed from left channel.52:21 Booking
Booking Booking for Ashley Chambers for unsporting behaviour.52:14
Ashley Chambers challenges Joe Widdowson unfairly and gives away a free kick.51:53
The ball is sent over by Joe Widdowson, clearance made by Tom Allan.50:31
Adam Reed has an effort at goal from just outside the box which goes wide of the right-hand upright.48:09
Jason Walker handles the ball and concedes a free kick. Direct free kick taken by Lee Nicholls.47:32
Ben Harding gives away a free kick for an unfair challenge on Tom Platt. Direct free kick taken by Michael Ingham.46:51
The official flags Jason Walker offside. Lee Nicholls restarts play with the free kick.45:01
The second half begins.45:00 +4:44 Half time
Half Time The referee calls an end to the first half.45:00 +0:53
Chris Hackett delivers the ball, drilled right-footed shot by Adebayo Akinfenwa. Save by Michael Ingham.43:28 Booking
Booking Michael Ingham goes into the book for time wasting.43:01
John Johnson challenges Ashley Chambers unfairly and gives away a free kick. Michael Ingham takes the direct free kick.42:14
Inswinging corner taken by Chris Hackett, save made by Michael Ingham.41:48
Jake Robinson takes the chance to get an effort at goal. Michael Ingham makes a fantastic save.40:45 Substitution
Substitution Jason Walker on for Richard Cresswell.38:37
Chris Hackett has an effort at goal from outside the area which goes wide left of the target.38:11
The assistant referee signals for offside against Roy O'Donovan. Direct free kick taken by Michael Ingham.37:25
Matty Blair has an effort at goal from inside the six-yard box that strikes the post.36:24
Adebayo Akinfenwa challenges Daniel Parslow unfairly and gives away a free kick. Michael Ingham takes the direct free kick.32:48
Headed effort from inside the area by John Johnson misses to the left of the target.32:17
Lee Collins takes the direct free kick.32:17 Booking
Booking Tom Platt booked for unsporting behaviour.32:06
Free kick awarded for a foul by Tom Platt on Jake Robinson.31:02
The referee blows for offside. Lee Nicholls restarts play with the free kick.29:52
The ball is swung over by Ashley Chambers, clearance by Adebayo Akinfenwa. Ashley Chambers takes a outswinging corner from the right by-line played to the near post, clearance made by Ben Harding.26:59
Shot by Matty Blair from 12 yards. Blocked by John Johnson. Corner taken right-footed by Ashley Chambers from the left by-line, Lee Collins makes a clearance. Outswinging corner taken right-footed by Ashley Chambers, Clarke Carlisle manages to make a clearance.26:05
Corner taken by Ashley Chambers from the right by-line, Lee Nicholls makes a save.23:16
Foul by John Johnson on Richard Cresswell, free kick awarded. Jack O'Connell takes the direct free kick.22:16
Jack O'Connell delivers the ball.21:24
Matty Blair takes a shot. Lee Nicholls makes a save. Inswinging corner taken from the left by-line by Ashley Chambers.20:12
The assistant referee flags for offside against Roy O'Donovan. Free kick taken by Michael Ingham.18:58
Inswinging corner taken by Ben Harding from the right by-line, clearance by Tom Platt.18:06
Inswinging corner taken right-footed by Chris Hackett from the left by-line, Clarke Carlisle takes a shot. Jack O'Connell makes a clearance.17:26
Adebayo Akinfenwa challenges Chris Smith unfairly and gives away a free kick. Free kick taken by Michael Ingham.11:39
The official flags Adam Reed offside. Direct free kick taken by Lee Nicholls.9:20
Matty Blair challenges Joe Widdowson unfairly and gives away a free kick. Chris Hackett delivers the ball from the free kick right-footed from left wing, Richard Cresswell manages to make a clearance.6:43 Goal scored
Goal! - Ashley Chambers - Northamp'n 0 - 1 York Ashley Chambers gets on the score sheet with a goal from inside the box to the bottom left corner of the goal. Northampton 0-1 York.4:39
Foul by Richard Cresswell on Clarke Carlisle, free kick awarded. Direct free kick taken by Lee Nicholls. Ben Tozer takes a shot. Save by Michael Ingham. Chris Hackett takes a short corner.3:24
Clarke Carlisle gives away a free kick for an unfair challenge on Richard Cresswell. Ashley Chambers produces a cross, Chris Smith takes a shot. Save by Lee Nicholls.2:23
The referee blows for offside. Free kick taken by Lee Nicholls.1:03
Adebayo Akinfenwa gives away a free kick for an unfair challenge on Tom Allan. Michael Ingham takes the direct free kick.0:00
The match gets underway.
Live data and text provided by our data suppliers