A Luis Suarez strike two minutes from time squeezed Liverpool into the group stage of the Europa League.
Hearts had led for three minutes thanks to a David Templeton strike that was spilled into his net by Pepe Reina.
But they could not hold out for extra-time as Suarez eventually notched the goal he had been threatening all match.
Hearts, though, will return to Edinburgh full of pride at their performance over the two legs.
Similar to the first leg, Hearts had plenty of early possession but they were carved open and almost fell behind after 14 minutes.
Jamie Carragher released Stewart Downing down the left and his deep cross was headed back across goal by Steven Gerrard. The lurking Suarez's subsequent header looked goal-bound but Marius Zaliukas got back to sweep the ball off the line.
Despite their status as massive underdogs, Hearts looked composed and a flowing move ended with Mehdi Taouil sending a shot tamely into the arms of Reina.
The visitors then had a decent claim for a penalty turned down when Callum Paterson tumbled under Carragher's challenge before Liverpool began to turn up the heat.
Adam Morgan's powerful effort from 25 yards was spilled by Jamie MacDonald but, with Gerrard bearing down on him, the keeper recovered to dive on the ball.
The Hearts man did even better on the half-hour mark as he rushed off his line to save from Gerrard, who had waltzed through three challenges on his way into the box.
Liverpool thought they had taken the lead shortly afterwards as Morgan tapped into an empty net, only for the assistant referee to indicate Suarez had carried the ball out of play before cutting it back.
Templeton was looking like Hearts' most threatening player, but he should have done better than hit high and wide when the ball dropped kindly for him 25 yards from goal just before the break.
Liverpool started the second half at a high tempo and carved out an early opportunity for Jonjo Shelvey, who rifled the ball just off target from outside the box.
Templeton shot Hearts into a surprise lead on 84 minutes
Hearts had defended superbly for the first hour but, as slackness began to creep in, Liverpool threatened to punish them.
Suarez rounded MacDonald after beating the Hearts offside trap but Ryan McGowan did brilliantly to get back and block the shot on the line.
Moments later Arvydas Novikovas lost out to Shelvey, allowing Suarez to turn and shoot, but once again his effort flew just wide, as did a ferociously whipped shot from Gerrard as the match entered the final quarter.
The pace and alertness of Suarez continued to cause problems in the Hearts backline and only evasive action from MacDonald prevented the Uruguayan profiting from another throughball, before the keeper used a leg to deny Gerrard at his near post.
Hearts chances by this stage were few and far between, so when Taouil was wasteful from just outside the box, the groans from the visitors' end were keenly felt.
But that anguish turned to rapturous joy five minutes from time when Templeton's speculative attempt from 25 yards squirmed from the grasp of the embarrassed Reina.
Suarez spared his keeper's blushes, though, when he raced clear three minutes later, evaded the challenge of Zaliukas and beat MacDonald from a narrow angle to send his side into the group stage of the Europa League.
Liverpool manager Brendan Rodgers:
"We achieved the objective which was to get through. They were two very tough games and they were never going to be easy.
"I thought the attitude and commitment of the players was excellent. We showed our spirit towards the end when we went behind. Our spirit really came through.
"I thought we were wasteful. We created chances and could have put the game to bed a lot earlier, but the most important thing was to get through and we have done that."
Full Time The final whistle goes and the game is over.
Short corner taken by Luis Suarez.
Steven Gerrard delivers the ball, clearance by Andy Webster.
Free kick awarded for a foul by Andy Webster on Luis Suarez. Luis Suarez restarts play with the free kick.
The assist for the goal came from Steven Gerrard.
87:23 Goal scored
Goal - Luis Suarez - Liverpool 1 - 1 Hearts Luis Suarez fires in a goal from inside the area to the bottom right corner of the goal. Liverpool 1 (2)-(1) 1 Hearts.
Steven Gerrard crosses the ball in from the free kick, Andy Webster makes a clearance.
Booking Daniel Grainger receives a yellow card.
Foul by Daniel Grainger on Raheem Sterling, free kick awarded.
84:03 Goal scored
Goal - David Templeton - Liverpool 0 - 1 Hearts A goal is scored by David Templeton from outside the box to the bottom left corner of the goal. Liverpool 0 (1)-(1) 1 Hearts.
Corner taken by Andrew Driver from the left by-line, Jonjo Shelvey makes a clearance.
Unfair challenge on David Templeton by Raheem Sterling results in a free kick. Strike comes in from Daniel Grainger from the free kick.
Steven Gerrard delivers the ball.
Jamie Carragher restarts play with the free kick.
Booking Darren Barr is cautioned by the ref for unsporting behaviour.
Darren Barr gives away a free kick for an unfair challenge on Joe Allen.
Mehdi Taouil produces a right-footed shot from just outside the area that goes harmlessly over the target.
The referee penalises Dale Carrick for handball. Jose Reina takes the direct free kick.
Indirect free kick taken by Jamie MacDonald.
Substitution Fabio Borini replaces Jordan Henderson.
Substitution Dale Carrick on for Arvydas Novikovas.
Martin Skrtel is caught offside.
Short corner worked by Steven Gerrard.
Raheem Sterling takes a shot. Blocked by Daniel Grainger.
Unfair challenge on Jordan Henderson by Andrew Driver results in a free kick. Free kick taken by Jordan Henderson.
Outswinging corner taken right-footed by Steven Gerrard from the right by-line, clearance by Ryan McGowan.
Steven Gerrard takes a shot. Jamie MacDonald makes a save.
Luis Suarez concedes a free kick for a foul on Jamie MacDonald. Indirect free kick taken by Jamie MacDonald.
Effort from a long way out by Steven Gerrard goes wide right of the target.
Raheem Sterling sends in a cross, Ryan McGowan manages to make a clearance.
Martin Kelly produces a cross, Marius Zaliukas makes a clearance.
Substitution Andrew Driver comes on in place of John Sutton.
Effort from outside the penalty box by Raheem Sterling goes wide left of the target.
Shot by Luis Suarez from deep inside the penalty area misses to the left of the target.
Jonjo Shelvey takes a outswinging corner from the right by-line to the near post, Callum Paterson manages to make a clearance.
Luis Suarez takes a shot. Blocked by Andy Webster.
Steven Gerrard takes a shot. Daniel Grainger gets a block in. Raheem Sterling sends in a cross, Jamie MacDonald makes a save.
Indirect free kick taken by Jamie MacDonald.
Substitution Raheem Sterling joins the action as a substitute, replacing Adam Morgan.
Luis Suarez concedes a free kick for a foul on Jamie MacDonald.
Centre by Arvydas Novikovas, Stewart Downing makes a clearance.
Outswinging corner taken right-footed by Steven Gerrard, Martin Skrtel produces a header from the edge of the box and misses to the left of the target.
Outswinging corner taken right-footed by Steven Gerrard played to the near post, clearance made by Daniel Grainger.
The ball is sent over by Stewart Downing.
The ball is crossed by Stewart Downing, clearance by Daniel Grainger.
Jordan Henderson takes a shot. Darren Barr gets a block in.
Ryan McGowan delivers the ball.
Free kick awarded for a foul by Jordan Henderson on David Templeton. Indirect free kick taken by Andy Webster.
Adam Morgan is caught offside. Jamie MacDonald takes the indirect free kick.
The ball is swung over by Stewart Downing, Marius Zaliukas manages to make a clearance.
Jonjo Shelvey has an effort at goal from outside the area which goes wide left of the target.
Jonjo Shelvey takes a shot. Marius Zaliukas gets a block in.
Outswinging corner taken right-footed by Steven Gerrard played to the near post, clearance made by Callum Paterson.
Corner taken by Steven Gerrard from the right by-line to the near post, Andy Webster manages to make a clearance.
Unfair challenge on Darren Barr by Jordan Henderson results in a free kick. Free kick taken by Jamie MacDonald.
The referee blows his whistle to start the second half.
45:00 +0:04 Half time
Half Time The ref blows to signal half-time.
Callum Paterson concedes a free kick for a foul on Jamie Carragher. Jamie Carragher takes the free kick.
Luis Suarez is flagged offside by the assistant referee. Direct free kick taken by Jamie MacDonald.
Free kick awarded for a foul by Jamie Carragher on Daniel Grainger. Free kick crossed by David Templeton, Jonjo Shelvey manages to make a clearance.
Outswinging corner taken right-footed by Steven Gerrard from the right by-line, Ryan McGowan makes a clearance.
Martin Kelly produces a cross, Daniel Grainger gets a block in.
David Templeton has shot on goal from just outside the box which goes wide of the right-hand upright.
The ball is swung over by David Templeton, save by Jose Reina.
David Templeton sends in a cross, Header by John Sutton from deep inside the penalty area misses to the left of the goal.
Unfair challenge on Steven Gerrard by Darren Barr results in a free kick. Free kick taken by Jose Reina.
David Templeton takes a shot. Blocked by Martin Skrtel.
Steven Gerrard takes a shot. Save by Jamie MacDonald.
Foul by Jamie Carragher on John Sutton, free kick awarded. David Templeton crosses the ball from the free kick right-footed from left channel, Andy Webster challenges Jamie Carragher unfairly and gives away a free kick. Jose Reina restarts play with the free kick.
Shot from 25 yards from Adam Morgan. Save by Jamie MacDonald.
Shot from just outside the box by John Sutton goes over the bar.
Luis Suarez gives away a free kick for an unfair challenge on Daniel Grainger. Daniel Grainger takes the direct free kick.
The ball is sent over by Martin Kelly.
Ryan McGowan challenges Jordan Henderson unfairly and gives away a free kick. Jonjo Shelvey takes the free kick.
Steven Gerrard takes a shot. Blocked by Marius Zaliukas.
Free kick awarded for an unfair challenge on Joe Allen by John Sutton. Free kick taken by Martin Skrtel.
Free kick awarded for a foul by Martin Kelly on Marius Zaliukas. Free kick taken by Jamie MacDonald.
Arvydas Novikovas crosses the ball, Mehdi Taouil takes a shot. Jose Reina makes a comfortable save.
The ball is swung over by Ryan McGowan.
Adam Morgan challenges Callum Paterson unfairly and gives away a free kick. Free kick taken by Daniel Grainger.
A cross is delivered by Jonjo Shelvey, clearance by Callum Paterson.
Inswinging corner taken by Steven Gerrard from the left by-line, save by Jamie MacDonald.
The ball is sent over by Stewart Downing, Luis Suarez takes a shot. Blocked by Marius Zaliukas.
The assistant referee signals for offside against Adam Morgan. Jamie MacDonald takes the direct free kick.
Arvydas Novikovas produces a cross.
The ball is sent over by Stewart Downing.
The ball is swung over by Daniel Grainger, Jonjo Shelvey manages to make a clearance.
David Templeton delivers the ball, Martin Kelly gets a block in.
Foul by Adam Morgan on Arvydas Novikovas, free kick awarded. Free kick taken by Daniel Grainger.
Corner taken right-footed by Steven Gerrard to the near post, Callum Paterson manages to make a clearance.
Luis Suarez takes a shot. Marius Zaliukas gets a block in.
Callum Paterson has an effort at goal from outside the box which goes wide left of the target.
The ref blows the whistle to start the match.
Live text and data provided by The Press Association
This page is best viewed in an up-to-date web browser with style sheets (CSS) enabled. While you will be able to view the content of this page in your current browser, you will not be able to get the full visual experience. Please consider upgrading your browser software or enabling style sheets (CSS) if you are able to do so.