A last-gasp goal by midfielder Jamie Brandon was enough for Livingston to get the better of Raith Rovers at Stark's Park.
The home side had the better chances, with Livingston goalkeeper Jerome Prior the much busier of the two goalkeepers, denying Callum Smith and Liam Dick.
Lewis Vaughan was introduced late on and he came closest for Raith with a header that came crashing back off the underside of the bar
Then with just seconds left, the visitors snatched a late winner.
A long ball was cleared to the edge of the box, where Jamie Brandon pounced and fired a low shot towards goal. Despite the best efforts of goalkeeper Kevin Dabrowski, he could not keep the ball out.
The win takes Livingston into third spot in the Championship, while managerless Raith Rovers now sit second-bottom.