Match ends, Rotherham United 2, Sheffield Wednesday 3.
Sheffield Wednesday scored two goals in injury time to inflict a damaging blow on Rotherham in their quest for Championship safety.
As the match entered stoppage time, the Millers were winning 2-1 through goals from Ben Pringle and Jordan Bowery.
But, after Caolan Lavery had earlier struck for Wednesday, Atdhe Nuhiu's header in the third minute of injury time levelled it at 2-2.
Kieren Lee's effort five minutes later won it for Wednesday.
With Fulham earning a victory 2-0 at Huddersfield, Rotherham's late collapse meant they slipped three points behind the west London side to sit one place outside the relegation zone.
And with Wigan picking up a point at home to Bolton, just five points separate the Millers from safety.
It was an enthralling end to the local derby as four goals went in after the 86th minute, but with three of those going Wednesday's way, Steve Evans will have to pick his side up after a fourth defeat in five games.
A 15-minute delay to kick-off only heightened the derby atmosphere and, in an open start, both goalkeepers were forced into fine saves, but Wednesday's Keiren Westwood and Rotherham's Emiliano Martinez, on loan from Arsenal, kept it scoreless at the break.
Evans' side made a strong start to the second period, and a lengthy spell of pressure was rewarded with Pringle's 57th-minute strike, which deflected off Tom Lees to wrong-foot the helpless Westwood.
The Millers came close to doubling their lead in the 64th minute but Jack Hunt's fierce effort went just wide.
The Owls offered little in response until the last 10 minutes when they finally stirred.
Four minutes from time, some fine wing-play from Lewis McGugan allowed him to cross for Lavery to head home.
Almost straight from kick-off the Millers thought they had won it again as Bowery picked the ball up on the left and shot home at the near post.
But Wednesday performed a late, late show as Nuhiu's header from a free-kick and Lee's breakaway goal meant they stole the win.
Rotherham boss Steve Evans:
"It's hard to take. For long spells we have out-worked, out-played Sheffield Wednesday and dominated a derby. The defending is poor for each of the goals, you can't defend like that in a football match.
"We are down because we didn't deserve that. We gave very, very sloppy goals away, it's disheartening. If you switch off you get punished, you just can't defend like that.
"We are as down as we can be. We are getting smashed, every decision goes against us, that's how it feels anyway."
Sheffield Wednesday manager Stuart Gray:
"If you're going to put subs on they have to have an impact.
"Credit to the three lads who went on, they have had a big impact (and) it probably just put Rotherham on the back foot, they went a little bit deeper and allowed my full-backs to get forward.
"When we put the three subs on I just felt it opened the game up for us. In the last 10 minutes it looked like we were the only team going to score."
- 30HuntBooked at 90mins
- 20MorganBooked at 75mins
- 27DerbyshireSubstituted forMilsomat 90'minutes
- 23SammonSubstituted forBoweryat 84'minutes
- 3MattockBooked at 20mins
- 27IsgroveSubstituted forLaveryat 58'minutes
- 4HutchinsonBooked at 44minsSubstituted forMaguireat 74'minutes
- 17HelanSubstituted forMayat 73'minutes
- Oliver Langford
- Shots on Target
Second Half ends, Rotherham United 2, Sheffield Wednesday 3.
Attempt saved. Stevie May (Sheffield Wednesday) right footed shot from a difficult angle on the left is saved in the bottom left corner. Assisted by Caolan Lavery.
Goal! Rotherham United 2, Sheffield Wednesday 3. Kieran Lee (Sheffield Wednesday) right footed shot from the centre of the box to the centre of the goal. Assisted by Stevie May.
Attempt saved. Stevie May (Sheffield Wednesday) right footed shot from very close range is saved in the bottom right corner. Assisted by Atdhe Nuhiu with a cross.
Attempt missed. Atdhe Nuhiu (Sheffield Wednesday) header from the centre of the box is close, but misses to the right. Assisted by Lewis McGugan with a cross following a corner.
Corner, Sheffield Wednesday. Conceded by Daniel Lafferty.
Goal! Rotherham United 2, Sheffield Wednesday 2. Atdhe Nuhiu (Sheffield Wednesday) header from the centre of the box to the bottom left corner. Assisted by Lewis McGugan with a cross following a set piece situation.
Jack Hunt (Rotherham United) is shown the yellow card for a bad foul.
Chris Maguire (Sheffield Wednesday) wins a free kick on the left wing.
Foul by Jack Hunt (Rotherham United).
Corner, Sheffield Wednesday. Conceded by Robert Milsom.
Attempt blocked. Chris Maguire (Sheffield Wednesday) right footed shot from outside the box is blocked. Assisted by Kieran Lee.
Substitution, Rotherham United. Robert Milsom replaces Matt Derbyshire.
Stevie May (Sheffield Wednesday) wins a free kick in the defensive half.
Foul by Jordan Bowery (Rotherham United).
Goal! Rotherham United 2, Sheffield Wednesday 1. Jordan Bowery (Rotherham United) right footed shot from the left side of the box to the bottom left corner. Assisted by Ben Pringle.
Goal! Rotherham United 1, Sheffield Wednesday 1. Caolan Lavery (Sheffield Wednesday) header from the centre of the box to the bottom left corner. Assisted by Lewis McGugan with a cross.
Substitution, Rotherham United. Jordan Bowery replaces Conor Sammon.
Attempt missed. Stevie May (Sheffield Wednesday) right footed shot from outside the box misses to the left. Assisted by Caolan Lavery.