The result brought to an end a club-record run of 10 consecutive home wins for the Dons.
Following a scrappy first half, Aberdeen were dominant after the break, but they were made to pay for their profligacy in front of goal when Kenny Miller scored a sublime opener in the 79th minute.
The 37-year-old striker added a second just over a minute later before substitute Joe Dodoo lashed home a third.
"It was a really important match for us," said Rangers manager Pedro Caixinha.
"We were facing a very strong side and they made a lot of problems for us."
The result brought to an end a club-record run of 10 consecutive home wins for the Dons and cuts their advantage over Rangers to nine points with six games left.
Aberdeen, with 15 wins in their previous 16 matches, had named an unchanged side for the fourth consecutive match, while Rangers brought in Miller and Jon Toral for Barrie McKay and Andy Halliday.
Encounters between these sides are always explosive and it took just three minutes for referee Kevin Clancy to make his first bookings after Ryan Jack and Joe Garner clashed following a challenge.
Martyn Waghorn blew a golden chance to fire Rangers in front when he got on the end of Garner's perfectly weighted cross, but blazed his effort over the bar from close range.
Aberdeen spurned an opportunity at the other end as Kenny McLean cut the ball back from the byline only for it to get stuck under Niall McGinn's feet.
The Dons started the second half on the front foot and only a fine save from Wes Foderingham kept a McLean shot on the half-volley from sneaking in.
Rangers had their goalkeeper to thank again moments later as he got down low to block Adam Rooney's angled drive.
Rooney was soon thwarted by Foderingham again when he made a superb one-handed save to keep the Irish striker's close-range volley out after he connected with Ash Taylor's headed flick-on.
The Dons were completely on top, but it was Rangers who took the lead against the run of play.
Joe Lewis made a good block to deny Waghorn, but the loose ball worked its way to Miller and the striker sent a ferocious half-volley screaming into the top corner.
Aberdeen had barely time to regroup before Miller doubled Rangers' advantage.
Anthony O'Connor's loose ball was seized upon by Dodoo and he dinked the ball into Miller's path for the veteran striker to slip a shot under the advancing Lewis.
The Dons had kept a clean sheet in their previous five games, but their defence fell to pieces as Dodoo added a third, cutting in from the left and rifling a shot low past the despairing Lewis.
Rangers nearly had a fourth in stoppage time when Dodoo robbed Taylor of possession and cracked a shot off the bar, with Miller's headed follow-up cleared off the line.
"I didn't feel under threat and I thought the goal was coming," said Aberdeen manager Derek McInnes said.
"Unfortunately for us we've played a part in our own downfall and gave away a poor goal and then had a crazy four or five minutes after that."