A thrilling final 20 minutes ended with Hearts edging out Livingston at Almondvale on Sunday.
The visitors led at half-time through a deflected effort by Bruno Aguiar after 17 minutes.
But Livi equalised when Sam Morrow got a slight touch on a Richard Brittain free kick just before the hour mark.
Edgaras Jankausas quickly headed Hearts back in front, but Dave Mackay levelled with a superb volley, only for Roman Bednar to strike a late winner.
Livingston started brightly and good work by Graham Dorrans allowed Sam Morrow an early shot at goal, but the former Hibs striker dragged his effort wide.
Moments later Greg Strong was allowed a free header on goal, only for the ball to sail over the bar.
Livingston were made to rue those misses when they fell behind to a somewhat fortuitous strike by Aguiar.
The ball fell to the Portuguese midfielder at the edge of the box and his shot deflected off the foot of the unfortunate Brittain, as he attempted to block the ball, and looped over Roddy McKenzie.
Bruno Aguiar is congratulated on Hearts' opener
The game quickly degenerated into a midfield battle and it was the 37th minute before Allan Walker managed the next shot on goal, but Craig Gordon stood up well to block the effort.
A couple of minutes before the break, McKenzie tipped over a superb long-range drive from Martin Petras.
The second half began in much the same vein as the majority of the first half, with goalmouth incidents at a premium.
But out of the blue, Livingston pulled level when a Brittain cross seemed to take the slightest of touches off the shoulder of Morrow on its way into the net.
Indeed Livingston might have gone ahead were it not for a fantastic save from Gordon to deny Walker from close range.
As the game entered the closing 25 minutes, both sides began to commit more men forward and Andy Webster was denied a header on goal by an important challenge by Manu Dorado.
But Hearts did go ahead following a fantastic move involving Robbie Neilson and Deividas Cesnauskis, whose cross was glanced into the net by Jankauskas.
McKenzie then did well to smother the ball at the feet of Rudi Skacel and that was to prove significant when Livi produced a second equaliser with 13 minutes remaining.
The ball sat up kindly for Mackay on the right of the penalty area and he volleyed an unstoppable shot past the despairing dive of Gordon.
But Hearts sealed the points three minutes from time when Bednar managed to hold off Jason Dair to power a shot past McKenzie.
Livingston: McKenzie, McNamee (Snodgrass 78), Strong, Dorado, Mackay, Brittain, Adams, Walker, Dair, Morrow, Dorrans (Hoolahan 70).
Subs Not Used: Roy, Miller, Geggan, Weir.
Booked: Morrow, Adams, Dair.
Goals: Brittain 59, Mackay 77.
Hearts: Gordon, Neilson, Berra, Webster, Fyssas, Cesnauskis (Beslija 86), Petras, Aguiar, Skacel (Hackett 82), Jankauskas (Bednar 75), Elliot.
Subs Not Used: Banks, McAllister, Johnson, Goncalves.
Goals: Aguiar 17, Jankauskas 72, Bednar 87.
Ref: J Underhill