Stockport kept their slim League Two survival hopes alive with a precious victory at promotion-chasing Port Vale.
The Hatters took the lead when Anthony Elding headed home from Matty Mainwaring's cross.
The hosts improved after the break and levelled when substitute Sean Rigg glanced a header in after Rob Taylor's excellent cross.
With time running out the visitors grabbed a dramatic late winner when Elding met James Wallace's free-kick.
Stockport are now six points adrift of 22nd placed Northampton Town with three matches to play.
Vale, who will be left ruing a number of missed chances, now sit in 10th place, three points outside the play-offs.
Port Vale caretaker manager Mark Grew told BBC Radio Stoke:
"I've just given them a few home truths of what I thought and some of them don't like it. Tough.
"You've got to have characters on the pitch and we haven't got enough characters or leaders.
"The teams I've been involved with, there have been leaders. They wanted to win badly and sometimes I'm not sure whether this side has got that in them."