Media playback is not supported on this device
Neilson, expected to join MK Dons, saw his side lead when Robbie Muirhead converted Bjorn Johnsen's cross.
Joe Dodoo volleyed into the Hearts net early in the second half but team-mate Harry Forrester was flagged offside.
Jamie Walker centred for an unmarked Muirhead to fire his second as Rangers' defensive frailties were once again laid bare.
A late Joe Garner header was nodded off the line by Faycal Rherras to preserve Hearts' clean sheet.
Victory meant that Hearts went ahead of Rangers on goal difference, with both sides eight points behind leaders Celtic, who have three games in hand.
The Tynecastle men visit Ross County on Saturday when Rangers host Aberdeen, who trail Mark Warburton's side by two points, but have played two games fewer.
Media playback is not supported on this device
The home side thrived by swarming all over Rangers' fragile defence. Their dominance was built on hustling and harrying the visitors, but rewarded by individuals being shrewd at critical moments.
Muirhead provided the finishing touches, but the towering displays came from Johnsen and Arnaud Djoum, whose accomplishment skewered Rangers.
Johnsen was unplayable at times, capable of bringing the ball down from head height and deftly flicking it into the penalty area and almost scoring.
The tall, gangly figure nearly broke the deadlock with a header that brought a flying save from Wes Foderingham, then was instrumental in Muirhead's opener, with a flick and then the cross that the attacker converted at the back post.
Djoum was peerless in midfield, keeping the ball in tight situations and never panicking in the bustle of the hole in front of the Rangers defence.
The second goal was a deftly executed counter attack, with Muirhead again finishing at the back post following Walker's delivery from the right.
Hearts barely let up and claimed fiercely, but in vain, for a penalty after Rherras went down just inside the box after getting the wrong side of substitute Michael O'Halloran.
For Neilson, on his likely swansong as Hearts boss, his side delivered a fitting farewell and the fans sang his name in tribute at the end.
James Tavernier was posted missing for both goals, but he was not alone in failing to deliver for the visitors. Only Foderingham - who kept the scoreline at two with a series of saves, including one that pushed a Johnsen second-half shot round the post - rose to the occasion.
Matt Crooks made his first start, but for a tall, physically imposing figure, he was unable to make his presence felt in midfield.
Rangers, who have kept just one clean sheet away from home on league duty this term, were never allowed to settle in the game, with Hearts pressing whenever Foderingham and the centre-backs had the ball, and the result was a disjointed performance.
There was a moment of frustration for the visitors when Dodoo's effort was ruled out, although it appeared an accurate call since Forrester was offside and in the line of sight of Hearts goalkeeper Jack Hamilton.
Even when Dodoo's replacement Garner turned a header towards the top corner late on, Rherras was on hand to clear.
Rangers had no answer to Hearts' assertive display. Even in possession, which Warburton emphasises, they were ragged and uncertain. It was unconvincing, and games are looming against Aberdeen and Hearts again.
Derby manager Steve McClaren took a seat in the directors box before the game, to watch Callum Paterson at first hand. The Hearts and Scotland right-back was occasionally defensively suspect, but he was also an attacking threat.
One run and shot in the first half forced Foderingham to cautiously push the ball away. And it was Paterson's bullet throw-in that created the headed chance for Johnsen in the first half.
Hearts know they are going to lose the player, either in the summer or in January if an offer comes in that is more than the development fee they would receive if he left as a free agent.
If there was a moment that summed the game up, it might have been Paterson winning a ferocious tackle with Andy Halliday in the first half, then surging upfield.
Halliday was left crumpled on the ground, complaining and helpless. His team were the same.
Hearts' Robbie Neilson: "It is not about me, it is about the players and the club getting second in the league, following recent relegation and the long journey, it is phenomenal for the whole club."
Read more from Neilson here.
Rangers' Mark Warburton: "Honesty is the best policy, you can mask over it and say we should have had the offside goal and we had one cleared off the line - no.
"Tonight as a group of players we didn't think we were good enough and what we have to do is respond very positively and look forward to the game against Aberdeen."
Match ends, Heart of Midlothian 2, Rangers 0.
Second Half ends, Heart of Midlothian 2, Rangers 0.
Attempt missed. Jason Holt (Rangers) right footed shot from outside the box is close, but misses to the right.
Foul by Arnaud Djoum (Heart of Midlothian).
Andy Halliday (Rangers) wins a free kick in the attacking half.
Callum Paterson (Heart of Midlothian) wins a free kick in the defensive half.
Foul by Joe Garner (Rangers).
Attempt missed. Joe Garner (Rangers) right footed shot from the centre of the box is close, but misses to the right.
Foul by Callum Paterson (Heart of Midlothian).
Jason Holt (Rangers) wins a free kick in the defensive half.
Substitution, Heart of Midlothian. Conor Sammon replaces Bjorn Johnsen.
Attempt blocked. Joe Garner (Rangers) right footed shot from the centre of the box is blocked.
Corner,  Rangers. Conceded by Jamie Walker.
Foul by Jamie Walker (Heart of Midlothian).
James Tavernier (Rangers) wins a free kick on the left wing.
Corner,  Rangers. Conceded by Arnaud Djoum.
Substitution, Heart of Midlothian. Liam Smith replaces Don Cowie.
Foul by Jamie Walker (Heart of Midlothian).
Joe Garner (Rangers) wins a free kick in the defensive half.
Substitution, Heart of Midlothian. Prince Buaben replaces Robbie Muirhead.
John Souttar (Heart of Midlothian) is shown the yellow card for a bad foul.
Foul by John Souttar (Heart of Midlothian).
Rob Kiernan (Rangers) wins a free kick in the attacking half.
Corner,  Heart of Midlothian. Conceded by Rob Kiernan.
Arnaud Djoum (Heart of Midlothian) wins a free kick in the defensive half.
Foul by Joe Garner (Rangers).
Attempt blocked. Jason Holt (Rangers) left footed shot from outside the box is blocked.
Foul by Bjorn Johnsen (Heart of Midlothian).
Andy Halliday (Rangers) wins a free kick in the attacking half.
Substitution, Rangers. Barrie McKay replaces Matt Crooks.
Substitution, Rangers. Joe Garner replaces Joseph Dodoo.
Foul by Robbie Muirhead (Heart of Midlothian).
Michael O'Halloran (Rangers) wins a free kick on the right wing.
Foul by Arnaud Djoum (Heart of Midlothian).
Danny Wilson (Rangers) wins a free kick in the attacking half.
Attempt saved. Bjorn Johnsen (Heart of Midlothian) right footed shot from the left side of the box is saved in the bottom right corner.
Substitution, Rangers. Michael O'Halloran replaces Harry Forrester.
Goal!  Heart of Midlothian 2, Rangers 0. Robbie Muirhead (Heart of Midlothian) left footed shot from very close range to the bottom left corner. Assisted by Jamie Walker.
Corner,  Heart of Midlothian. Conceded by Lee Wallace.
Corner,  Heart of Midlothian. Conceded by Wes Foderingham.
Hearts beat Rangers to go second in the Scottish Premiership in what could be Robbie Neilson's last match in charge.