Zac Sapsford's stoppage-time penalty sealed an unlikely comeback victory for Dundee United to deny Livingston a first Scottish Premiership win since August and edge their apparently inevitable relegation even closer.
Lewis Smith's second-half double looked to have given the visitors a real chance of a first triumph since the summer, cancelling out Will Ferry's opener.
But Krisztias Keresztes headed in a 75th-minute equaliser for haphazard United before Sapsford's penalty won it with the last kick of the game.
The win keeps United in seventh, and all-but removes them from the relegation equation, but Livingston are now 12 adrift of Kilmarnock with 15 points to play for.
United boss Jim Goodwin had made four changes from the team that lost at Ibrox last week, and they continued their decent form of late, taking a 19th-minute lead.
Max Watters played the ball out to Ferry in acres of space on the left. He carried the ball into the box, shifted on to his right foot and rifled a low shot past Jerome Prior.
Livingston remained well-organised and weren't lacking effort but United looked on top until the end of the half, when Livingston served notice of the threat they could carry from set pieces.
Soon after the restart, Marvin Bartley's side got their reward. Joel Nouble robbed Iurie Iovu out wide, and cut the ball back for Smith to hit a high finish into the net.
Moments later, Smith struck again. Goalkeeper Prior spotted an opportunity and hit a long ball down the middle, leaving Smith one on one with Ross Graham. The winger unleashed a powerful low shot that left Richards without a chance.
With no league wins since August, Livingston perhaps understandably tried to defend their lead. But United found an equaliser when Keresztes rose highest to bullet in Ferry's corner.
The drama wasn't over though, and in the final minute, Brooklyn Kabongolo fouled Sapsford to concede a penalty and give United a late chance to win it.
The Australian forward stepped up and made no mistake to leave Livingston with what looks like an impossible job to avoid a return to the Championship.