Ross Caldwell's last-minute winner extended Hibernian's unbeaten run against their city rivals Hearts to five games.
The 19-year-old was handed just his second start but repaid manager Pat Fenlon's faith with his sensational strike.
The final SPL meeting of the sides this season looked set to end in a fourth stalemate after Leigh Griffiths' stunning free-kick two minutes after half-time cancelled out Darren Barr's 44th-minute opener for Hearts.
It was the defender's first goal since he struck the first in the Jambos' 5-1 rout of their rivals in last May's William Hill Scottish Cup final.
But Hibs - who are preparing for their second successive final appearance later this month - ensured they retain the bragging rights as they added to their January cup triumph with a second victory over Hearts this season as well as overtaking Gary Locke's men to steal ninth place in the table.
Talk before the game had centred on whether Hearts' young players, pushed into the side as a result of their continuing financial problems, could handle Griffiths as he made his final Edinburgh derby appearance before returning to parent club Wolves in the summer.
The Scotland frontman required three goals to become the first Easter Road attacker in 40 years to find the net 30 times in a season but he found his involvement limited in the first half.
Hearts full-back Kevin McHattie saw his corner dropped by Hibs goalkeeper Ben Williams as he struggled to get a grip on the slippery ball. Barr and Michael Ngoo both had a stab at prodding it over the line but Alex Harris and Lewis Stevenson came up with the last-ditch clearances to save the visitors.
Hibs midfielder Kevin Thomson then had a half-hearted penalty appeal turned down by referee Steven McLean after tussling with Ryan Stevenson, while MacDonald adjusted well after Caldwell's shot from the edge of the box took a nick off Hamill's boot.
Jamie Walker flashed a shot over Williams' crossbar from 20 yards out with six minutes of the half remaining and the opener as the game moved into the final minute of the period.
Williams lost the flight of McHattie's corner towards the back post and while Ngoo saw his point-blank range header stopped on the line by Tom Taiwo, Barr was there to smash home the rebound.
Fenlon had words with McLean going down the tunnel, claiming Thomson had been pushed by Hamill in the build-up to the corner, but replays showed the former Scotland man had slipped.
Griffiths, however, would finally make his mark just two minutes into the second period. A Mehdi Taouil barge on Harris teed up the striker to shoot from 25 yards out and his set-piece effort was simply stunning as it skimmed over the Hearts wall and past MacDonald on its way to the top corner.
A draw looked increasingly likely until Caldwell came up with his decisive strike.
Griffiths charged down Hamill's clearance and the ball broke to substitute Scott Robertson before bouncing onto the teenage striker, who swept the ball into the top corner to cue bedlam in the away end.