Dundee United scored very early and very late to snatch all three points in a game that Livingston almost completely dominated.
With over 92 minutes gone, and a draw looking likely, Jim McIntyre - who had nodded United in front after 90 seconds - crossed for skipper Charlie Miller to scramble the ball over the line from point blank range.
Miller's winner takes relegation-threatened United four points clear of Motherwell at the foot of the SPL with just two games remaining.
Livingston responded positively to McIntyre's early strike and midfielder Lee Makel tested United keeper Alan Combe with a string of long-range drives.
McIntyre created an excellent chance which Derek Lilley directed too close to keeper Alan Main, but the home side was getting on top and top scorer Rolando Zarate rounded off a superb move by setting up Argentinian Fernando Pasquinelli whose header brought a fine save from Combe.
The keeper was involved again after 34 minutes as he somehow kept out a marvellous left-footed shot from Canadian David Xausa.
United were being out-classed but midfielder Russell Latapy suddenly had a golden opportunity to make it 2-0 when the ball ran perfectly for him 15 yards out. For some reason, the former Rangers player did not shoot immediately and switched feet twice before firing just wide.
The standard dipped after half-time, but Livingston kept pushing and youngster Burton O'Brien was not too far away with a curling effort. Captain Stuart Lovell was desperately unlucky in the 58th minute when he rattled the crossbar with a fierce left-foot volley.
The equaliser had to come and substitute David Bingham supplied it with 12 minutes left when he headed home after full back Philippe Brinquin had picked him out with a perfect cross from the right.
But they were to fall to Miller's late, late strike.