Aberdeen recorded their first league win over Rangers since 1998 in a fascinating game at Pittodrie.
The home side went two ahead through a Russell Anderson header and a Steve Lovell effort from close range, before Dado Prso headed in for Rangers.
Peter Lovenkrands' terrific overhead kick drew the visitors level but they then had Fernando Ricksen sent off for a second yellow card.
And with full-time looming, Jamie Smith drove in the winner from 25 yards.
Ricksen had provided the first attempt on goal after six minutes.
Aberdeen keeper Ryan Esson came off his line to try to collect a Barry Ferguson free kick but got nowhere near it and as the ball fell to Ricksen, he lobbed it goalwards, only for Anderson to head clear.
Moments later Nacho Novo saw a chip from the edge of the box sail just over the bar.
The game became very scrappy for a period, with tempers fraying at times, but the first goal arrived to raise the standards after half-an-hour.
Gary Dempsey's free kick was met by Bob Malcolm, but his attempted clearance came off the chest of Anderson and the Aberdeen captain showed great bravery to dive headlong to nod the ball over the line.
If the Rangers defence looked shaky conceding that first goal, it was torn apart as Aberdeen doubled their lead.
Barry Nicholson's pass to Lovell took Julien Rodriguez out of the game, and the striker's first touch took him past Malcolm before he tucked the ball past Ronald Waterreus.
Steve Lovell is mobbed after scoring Aberdeen's second
The home side's two-goal lead was short-lived though. Ricksen's inswinging corner was met by the head of Prso to bring Rangers immediately back into the game.
Rangers looked fired up at the beginning of the second half and it took them only four minutes to draw level.
Steven Thompson, on for Malcolm at half-time, did well to get in a cross from the left at the second attempt and Lovenkrands leapt to acrobatically scissor-kick the ball past Esson.
Rangers' hopes of taking all three points were dented, though, when Ricksen, who had been booked in the first half for a series of fouls, was ordered off for blocking the run of Kevin McNaughton.
Shortly afterwards, Lovell had the ball in the net again, but he was correctly ruled offside.
The game hit a lull after that and seemed to be heading for a draw until, with just two minutes of regulation time remaining, Smith picked up on Maurice Ross' scuffed clearance to drill a superb winner past Waterreus.
Aberdeen: Esson, Severin, Diamond, Anderson, Nicholson, Dempsey (Stewart 81), Clark, McNaughton, Muirhead (Foster 79), Lovell (Craig 73), Smith.
Subs Not Used: Langfield, Winter, Donald.
Booked: Nicholson, Diamond.
Goals: Anderson 30, Lovell 37, Smith 88.
Rangers: Waterreus, Pierre-Fanfan, Malcolm (Thompson 45), Rodriguez, Ball, Ricksen, Ferguson, Murray, Lovenkrands (Ross 74), Novo (Alex Rae 61), Prso.
Subs Not Used: Klos, Adam, McCormack, N'Guessan.
Sent Off: Ricksen (55).
Booked: Lovenkrands, Malcolm, Ricksen, Thompson.
Goals: Prso 39, Lovenkrands 49.
Ref: J Underhill