The Lions had led through former Hibernian midfielder Marvin Bartley's 33rd-minute opener.
The managerless Gorgie side were heading to a third straight loss and second bottom of the Ladbrokes Premiership before substitute MacLean pounced on a loose ball inside the area to score in the 88th minute as the game finished 1-1.
Hearts piled on the pressure in the early stages and registered three shots on target inside the first 14 minutes, having only managed one during their entire trip to Ibrox.
The first opportunity arrived inside the first minute when Jamie Walker connected with Steven Naismith's flick inside the area but the playmaker's left-footed volley was comfortably saved by Matija Sarkic at his near post.
Lions goalkeeper Sarkic got behind a stinging Naismith drive from an angle just inside the box before the hosts wasted an even better chance in the 11th minute.
Michael Smith's corner found the unmarked Halkett in the box but the centre-half inexplicably headed wide from just six yards.
Hearts were forced into a change after just 26 minutes when Naismith was replaced by MacLean.
Livingston had barely been in the game but Gary Holt's side stunned Tynecastle with a 33rd-minute opener from former Hibernian favourite Bartley.
Livingston had their tails up at the start of the second half and came within inches of grabbing a second when Stevie Lawless hit a low shot just past Zlamal's post.
The towering forward was involved in the 69th minute when he got on the end of Glenn Whelan's free-kick but Sarkic dived to his right to make the save.
Livingston looked just as likely to grab a second and Hearts defender Berra did well to make a timely block on Lawless' goal-bound effort.
At the other end, Sarkic was again called into action, this time pulling off a brilliant saved to push Whelan's strike from 20 yards behind for a corner.
Hearts finally levelled with two minutes left when MacLean lashed home from close range after Livingston failed to clear Whelan's corner.