Queen of South won to move off the bottom of the First Division table and above opponents Ayr United.
Stephen McKenna curled in an unstoppable effort from distance to give Queens a 31st-minute lead.
Gareth Wardlaw swept home Ayr's leveller on the stroke of half-time.
The visitors' Eddie Malone was sent off for a foul on Nicky Clark and Scott McLaughlin converted the resulting penalty on 71 minutes.
Daniel Carmichael quickly grabbed the hosts' third and Stephen Simmons' right-foot shot completed the scoring late on as Raith Rovers were sent bottom of the division. Ayr stay ninth.
Queen of South: Robinson, Holt, Craig Reid, Higgins, Carmichael, McKenna, Simmons, McLaughlin, Alan Reid, Johnston (Clark 64), Brighton (Smith 64). Subs Not Used: McKenzie, McCusker, Black.
Goals: McKenna 31, McLaughlin 71 pen, Carmichael 72, Simmons 89.
Ayr: Cuthbert, Tiffoney, John Robertson, Smith, Malone, Trouten, McKernon, Geggan, McGowan (Connolly 78), Moffat (McManus 78), Wardlaw (Roberts 85). Subs Not Used: McWilliams, Ross Robertson.
Sent Off: Malone (70). Booked: Wardlaw, McManus.
Goals: Wardlaw 45.
Ref: Steven McLean