Mark Burchill claimed a hat-trick as Dunfermline Athletic came from behind to all but relegate Livingston.
Livi claimed Noel Hunt handled the ball on the line
Richard Brittain gave Livi a ninth-minute lead from the spot after Greg Ross pulled back Wes Hoolahan.
That was cancelled out by Burchill after the striker had been fouled in the box by goalkeeper Roddy McKenzie.
Colin Healy's 20-yard drive put Livi back ahead, but Burchill drove in the equaliser and headed the winner that moved the Pars closer to safety.
It leaves Livi nine points behind both Dunfermline and Falkirk with three games remaining, but John Robertson's side have an inferior goal difference.
Both sides had problems before kick-off.
Midfielder Lee Makel's hopes of returning for injury-hit Dunfermline were thwarted by an overnight accident with a dustbin.
And Livingston's team bus was held up in traffic, forcing a 14-minute delay to the start of the match.
But John Robertson's unchanged side, arriving on the back of two straight victories, still managed to quickly assume the ascendency.
Noel Whelan fired over from a tight angle then crossed for Allan Walker to head over.
And, in the ninth minute, referee Stuart Dougal pointed to the spot when Hoolahan was felled by Ross, who was returning to the Pars side along with Gary Mason and Bartosz Taraschulski.
Striker Mark Burchill is claiming the winning goal
Up stepped Brittain and made no mistake from the spot.
The Pars fought back and Tarachulski headed over then referee Stuart Dougal rejected a penalty claim after the ball struck Walker's arm.
And Noel Hunt sent a drive from the edge of the box fizzing just wide before the Pars eventually grabbed the equaliser.
McKenzie brought Burchill down as the striker nipped in with Harald Pinxten in pursuit and former Celtic man slotted the equaliser home.
Scott Wilson was just wide with a diving header from Scott Thomson's free-kick as Dunfermline took control.
McKenzie had to make a fine stop to prevent Muirhead from capitalising on a mis-placed clearance by Mackay.
And Burchill fired across the goalmouth from the resulting corner.
But Livi were first to threaten after the break, half-time substitute Steven Hislop scooping the ball over from 12 yards and Healy curling an effort wide from 25 yards.
Healy did much better with his next attempt, driving in from distance off the right-hand post.
But Burchill equalised, pouncing after McKenzie had blocked an effort from Taraschulski.
And the striker headed the winner, although Livi players protested that Hunt had scrambled the ball over the line at the back post with his hand.
Dunfermline: McGregor, Labonte, Shields, Scott Wilson, Thomson, Ross, Mason, Muirhead (Daquin 73), Hunt (Tod 90), Burchill, Tarachulski.
Subs Not Used: Halliwell, Phinn, Iain Campbell, Andy Campbell, Camano.
Goals: Burchill 38 pen, 78, 85.
Livingston: McKenzie, McNamee (Tierney 87), Pinxten, Strong, Mackay, Brittain, Healy, Walker, Hoolahan, Morrow (Hislop 45), Whelan.
Subs Not Used: Woods, Adams, Scott, Miller, Dorrans.
Booked: Mackay, Strong.
Goals: Brittain 9 pen, Healy 63.
Ref: S Dougal