Scott Arfield's astonishing stoppage-time double snatched Rangers a dramatic Scottish Premiership victory over Aberdeen and prevented their fragile title hopes from splintering further.
Stunning goals from Duk and Leighton Clarkson had hauled Aberdeen into the lead as the game crept into seven added minutes, with Fashion Sakala having earlier put Rangers in front.
But Arfield followed in when goalkeeper Kelle Roos spilled Ryan Kent's shot, and then capitalised on a defensive error to bundle in a frantic winner.
It puts Rangers six points behind Celtic - who play Livingston on Wednesday - when it looked likely they would at least be eight points behind having played a game more.
And it gives new manager Michael Beale a huge boost, having secured two 3-2 comeback wins in his first two games in charge.
Aberdeen stay third, but were left absolutely devastated, with manager Jim Goodwin crouching on the floor in disbelief at full-time at how his side had managed to throw away what looked like being a first win in 13 attempts against Rangers.
The Pittodrie side took a lot of criticism for their defensive approach on Saturday against Celtic, when they eventually succumbed to a late goal, but after a sluggish first 20 minutes during which Sakala lashed in at the second attempt, they came to life and took control.
Duk's unorthodox free kick wrong-footed Allan McGregor and brought them level just before half-time, which was no less than they deserved in a feisty and full-blooded contest with 10 yellow cards.
And Goodwin's side came out after the restart with the momentum behind them, taking the lead when Liverpool loanee Clarkson swept the dropping ball into the corner to add to his growing highlights reel.
But Beale made four changes - including bringing on Arfield - and Rangers grew back into the game as Aberdeen dropped deeper with something to cling on to.
They were five minutes from getting a victory but goalkeeper Kelle Roos spilled Kent's 20-yard shot and Arfield reacted quickest to ram home, and the midfielder was lurking again when Anthony Stewart and Jayden Richardson failed to deal with Malik Tillman's cross, thumping his shot into the ground and over Roos.
Beale spoke of a big 'mentality week' for Rangers, and his team ultimately responded. But Aberdeen's mentality to throw away such a promising position they had worked so hard to build will be questioned.
Player of the match
Nobody had more touches in the Aberdeen box, or shots on target than Arfield, who only came on in the second half. Plus the small matter of his two stoppage-time goalsRangers come back again but work to do - analysis
No side in the Premiership has claimed more points from losing positions than Rangers this season. It shows their persistence and character, but also their fragility.
After a good start they looked nervous when Aberdeen came at them, and for a long time they didn't look like they had the answers they needed.
But Arfield was the one who made the difference. Even before his goals he showed his willingness to get into the box and run beyond the defence, and had two good chances.
He kept going and got his rewards. Beale knows he has a lot of work to do to improve this team, but as that work goes on all the team can do is keep in touch with Celtic.
As for Aberdeen, their season could be defined by how they respond to this devastating defeat. They were so much more aggressive and forward-thinking than they were against Celtic, and caused a frail Rangers defence lots of problems.
But it's hard to escape the conclusion they dropped too deep too early, when they had Rangers on the ropes. Then again, Goodwin cannot compensate for two individual errors at the death.
There is potential and talent in the team, but defensive lessons will need to be learned quickly if they want to achieve a top-four finish and end the season with a chance of silverware.
What they said
'It's difficult to understand what happened at the end'Aberdeen manager Jim Goodwin: "It is very difficult to understand what happened in the final three or four minutes of that game.
"Now is not the time to talk about positives, because that is not what people want to hear, but I thought the boys played well at times, more intensity to the game and we deserved to take the lead."
Rangers manager Michael Beale: "It was 10/10 in terms of mentality and character, 5/10 for performance.
"We are playing in patches rather than controlling the whole game. Defensively, we still need to tighten up. But, away from home, three points is all that matters at the moment and, with time and confidence together, we will surely improve."
'Rangers 10/10 for character, but 5/10 for performance'What's next?
Aberdeen must pick themselves up on Saturday when they face St Mirren in Paisley (12:30 GMT), while Rangers travel to Dingwall to face Ross County on Friday (19:30) looking to continue their momentum.
Player of the match
ArfieldScott Arfield
Aberdeen
Squad number11Player nameDuk
Squad number20Player nameClarkson
Squad number2Player nameMcCrorie
Squad number22Player nameCoulson
Squad number8Player nameBarron
Squad number16Player nameRamadani
Squad number5Player nameStewart
Squad number24Player nameRoos
Squad number4Player nameScales
Squad number17Player nameHayes
Squad number25Player nameRichardson
Squad number9Player nameMiovski
Squad number3Player nameMacKenzie
Squad number15Player nameWatkins
Squad number7Player nameMorris
Rangers
Squad number37Player nameArfield
Squad number44Player nameDevine
Squad number14Player nameKent
Squad number30Player nameSakala
Squad number71Player nameTillman
Squad number8Player nameJack
Squad number6Player nameGoldson
Squad number18Player nameKamara
Squad number1Player nameMcGregor
Squad number2Player nameTavernier
Squad number26Player nameDavies
Squad number20Player nameMorelos
Squad number4Player nameLundstram
Squad number19Player nameSands
Squad number23Player nameWright
Line-ups
Aberdeen
Formation 3-5-2
24Roos
2McCrorie5Stewart4Scales
25Richardson8Barron16Ramadani20Clarkson22Coulson
9Miovski11de Barros Lopes
24Roos2McCrorie5Stewart4ScalesBooked at 24mins25RichardsonBooked at 71mins8BarronBooked at 35mins16RamadaniBooked at 21mins20ClarksonSubstituted forMorrisat 65'minutes22CoulsonSubstituted forMacKenzieat 81'minutes9MiovskiSubstituted forWatkinsat 65'minutesBooked at 90mins11de Barros LopesSubstituted forHayesat 65'minutesSubstitutes
1Lewis3MacKenzie7Morris10Besuijen15Watkins17Hayes23Duncan28Milne99RamírezRangers
Formation 4-2-3-1
1McGregor
2Tavernier6Goldson19Sands44Devine
18Kamara8Jack
30Sakala71Tillman14Kent
20Morelos
1McGregor2Tavernier6Goldson19SandsBooked at 42minsSubstituted forArfieldat 58'minutesBooked at 90mins44Devine18KamaraSubstituted forDaviesat 58'minutes8JackBooked at 21minsSubstituted forLundstramat 58'minutesBooked at 71mins30SakalaSubstituted forWrightat 58'minutes71Tillman14Kent20MorelosBooked at 90minsSubstitutes
4Lundstram17Matondo23Wright26Davies29McCann33McLaughlin37Arfield38King51LowryReferee:William CollumAttendance:18,025Live Text
Match ends, Aberdeen 2, Rangers 3.
Second Half ends, Aberdeen 2, Rangers 3.
Alfredo Morelos (Rangers) is shown the yellow card for excessive celebration.
Goal! Aberdeen 2, Rangers 3. Scott Arfield (Rangers) left footed shot from the right side of the six yard box to the high centre of the goal. Assisted by Connor Goldson.
Attempt missed. Ylber Ramadani (Aberdeen) right footed shot from outside the box is close, but misses to the left following a set piece situation.
Foul by Scott Arfield (Rangers).
Ross McCrorie (Aberdeen) wins a free kick in the attacking half.
Goal! Aberdeen 2, Rangers 2. Scott Arfield (Rangers) left footed shot from very close range to the bottom left corner.
Attempt saved. Ryan Kent (Rangers) left footed shot from outside the box is saved in the centre of the goal. Assisted by Connor Goldson.
Foul by James Tavernier (Rangers).
Jonny Hayes (Aberdeen) wins a free kick in the defensive half.
Marley Watkins (Aberdeen) is shown the yellow card.
Offside, Aberdeen. Jonny Hayes tries a through ball, but Marley Watkins is caught offside.
Scott Arfield (Rangers) is shown the yellow card for a bad foul.
Foul by Scott Arfield (Rangers).
Ylber Ramadani (Aberdeen) wins a free kick in the attacking half.
Attempt saved. John Lundstram (Rangers) left footed shot from outside the box is saved in the centre of the goal. Assisted by Connor Goldson.
Foul by Malik Tillman (Rangers).
Marley Watkins (Aberdeen) wins a free kick in the attacking half.
Foul by Scott Wright (Rangers).