Dan Mackay handed Livingston their first win in 14 games as the Premiership side came from behind to beat Raith Rovers 2-1.
The on-loan Hibs forward headed home in the 82nd minute of an entertaining contest to send the Lions into the Scottish Cup fifth round.
Mackay, who replaced the injured Cristian Montano in the first half, also set up Jamie Brandon for his team’s equaliser after Jack Hamilton gave Championship title hopefuls Raith the lead after only five minutes.
Rovers more than held their own against their top-flight counterparts, who also missed a first-half penalty through Andrew Shinnie, but the hosts showed great character to earn a much-needed morale-boosting win.
Raith came flying out of the blocks and had two good chances even before they broke the deadlock.
Lewis Vaughan got the byline and swung in a low teasing cross that Hamilton failed to bundle in from close range.
The pair combined again moments later as hitman Hamilton nodded the ball down to his team-mate but Vaughan’s shot from close range was repelled by Shamal George.
The Lions failed to heed those warnings and Hamilton opened the scoring.
Ross Millen lumped a long ball forward and the striker had time to chest it down before firing a low shot through the legs of Lions goalkeeper George.
Livingston finally began to settle following an erratic start but it was Raith who went close to adding a second.
Aidan Connolly launched a left-footed drive from outside the box just past the post.
Livingston then wasted a great chance to level from the penalty spot in the 21st minute.
Shinnie was brought down by Kyle Turner after dispossessing the midfielder.
The experienced midfielder took the spot kick himself but his effort hit the post and rebounded off keeper Kevin Dabrowski before rolling to safety.
But Livingston did level in the 33rd minute through Brandon. ]
Mackay, who only came on for the injured Montano minutes earlier, found the wing-back at the back post and Brandon lashed a shot past Dabrowski.
The action was end-to-end in the second half too. Raith had chances through Connolly and Callum Smith before Vaughan hit a free-kick over the bar.
At the other end Stephen Kelly should have at least hit the target from 12 yards when he connected with Mackay’s cut back but the midfielder fired well over.
Raith full-back Liam Dick then had a shot palmed over before the hosts grabbed the winner.
Kelly lifted a teasing cross into the area and Mackay headed a powerful effort past Dabrowski from six yards.