Super sub Darren Gribben smashed home a late winner as Forfar followed up their win over Champions Gretna a week earlier with another scalp.
Gribben pounced with 10 minutes to go, driving home a low shot after David Keogh's effort had been only parried by keeper Mark McGeown.
Forfar dominated the first half and Paul Lunan and Michelle Lombardi had net-bound headers scrambled off the line as Ayr struggled to make headway.
Forfar continued on top at the start of the second half and a shot from Andy Jackson took a wicked deflection before spinning on to the bar.
Ayr thought they had grabbed an unlikely win in 58 minutes when Chris Strain drove home from a tight angle but their celebrations were halted when the linesman flagged for offside.
After Gribben's goal Ayr went flat out for the equaliser and in the final minute Chris Robertson had a powerful header superbly saved by keeper Michael Brown.
After the game Ayr boss Robert Connor said: "It was a disappointing way to end at home. Next season is going to be big for us and we are going to have to do a lot better."
Forfar boss Ray Farningham said: "It was a typical end of season game but I thought we just deserved the three points."