Sheffield Wednesday boss Garry Monk said his side “got what we deserved” after conceding twice in injury time to lose at Stoke.
The Potters first went in front when James McClean struck from close range.
Wednesday then turned the game on its head after the break with Morgan Fox and Tom Lees both scoring from corners.
But Tyrese Campbell levelled the match before Sam Vokes scrambled home the winner in the 97th minute to lift Stoke out of the Championship drop zone.
“We were not at the races at all,” said Monk. “Very frustrating to have the lead and come off with defeat.
“We are bitterly disappointed, competed better in the last 30 minutes, but not good enough today.
“There was always going to be a fight from them and we did not match that for the first 60 minutes.”
An incredible finish saw four goals in 30 minutes, but there was little hint of the excitement to come as Stoke looked to hang on to their first-half lead for a sixth league win of the season.
The Potters had controlled possession in the early stages and capitalised when Owls defender Dominic Iorfa gave the ball away, allowing Joe Allen to hit a volley towards goal, which found McClean, who tapped the ball home from almost on the line.
McClean then tried to turn provider, sending in two good crosses from the left, but Lee Gregory headed wide both times.
Wednesday sprung to life just before the half-time whistle when Adam Reach hit the post after being set up by Kadeem Harris.
Monk’s side had struggled to deal with the creativity of their hosts but grew in confidence in the second half and Fox flicked in Barry Bannan’s corner at the near post to make it 1-1 after 67 minutes.
Seven minutes later, another corner saw Stoke goalkeeper Jack Butland save a header from Sam Winnall, only for Lees to nod home the rebound.
But three minutes into stoppage time, an acrobatic volley from substitute Campbell beat Butland’s opposite number Cameron Dawson.
And just as it looked as though the points would be shared, Vokes poked the ball in on the line to lift Stoke off the bottom and up to 21st place in the table with their first win against Sheffield Wednesday in eight attempts.
Stoke City manager Michael O’Neill:
“I thought we were the better team throughout the game. We were very good in the first half, deserved to be ahead, and probably should have been more than one ahead.
“(Then) we lose two goals, the first one is a bit of a freak goal the way it goes in. The second one, obviously it is a great ball in, difficult for us to defend.
“But I felt it was very very harsh on us. We have to fight our way back into the game but that is the character that is needed. That is the character hopefully that can help us move up away from the position we are in.”