Ayr capitalised on some poor goalkeeping to take the three points.
The visitors took the lead when Chris Fahey spilled a cross and Alex Williams fired into the net. The keeper then shipped a Chris Robertson goal.
Ayr made the points safe when Ryan Stevenson netted from the edge of the box after a slick counter-attack.
Raith rallied briefly and Steven Hislop reduced the deficit with a five-yard strike and got his second from the spot with the last kick of the ball.
Raith: Fahey, Wilson, Pelosi, Campbell, Andrews, Tod, Davidson, Winter (Sloan 84), Hislop, Weir (Carcary 69), Silvestro. Subs Not Used: Dingwall, Helley, Amos.
Goals: Hislop 89, 90 pen.
Ayr: Corr, Pettigrew, Swift, Forrest, Henderson, Stevenson, Vareille (Hamilton 73), Robertson, Moore (Wardlaw 81), Williams, Dunn (Casey 90). Subs Not Used: Weaver, McGeown.
Booked: Vareille, Forrest.
Goals: Williams 11, Robertson 19, Stevenson 59.
Ref: S Conroy