Brian Graham's late free-kick secured 10-man Raith's passage into the fifth round after a 2-1 win over Deveronvale.
The Highland League outfit were minutes away from earning a replay before Graham's 30-yard free-kick rescued the first division side.
The visitors got to half-time unscathed but Graham opened the scoring 10 minutes into the second period, heading in David Smith's corner from close range.
But the game swung just two minutes later. Douglas Hill brought down Kris Duncan in the penalty area and received a straight red card, and Scott Fraser coolly tucked his spot-kick into the bottom left corner to level the scores.
With a replay in sight, Craig Cowie was adjudged to have fouled Greig Spence 30 yards out and Graham's effort found the top corner of Darren McConnachie's goal to knock the minnows out.