Martyn Fotheringham scored an 89th-minute winner as Forfar edged a five-goal Second Division thriller at Somerset Park.
Ayr United were searching for their first league victory of the season and took the lead just six minutes into the game when David Sinclair found the top corner from the edge of the area.
Iain Campbell's penalty pegged Mark Roberts' men back in first-half stoppage time after John Robertson had impeded Chris Templeman.
The Honest Men went ahead for the second time after 52 minutes when Sinclair smacked a 20-yard free-kick past Loons goalkeeper Derek Soutar.
Ross Campbell set Gavin Swankie through seven minutes later and Forfar's top goalscorer kept a cool head to bag his fourth goal of the campaign.
The match looked to be heading for a draw until Fotheringham got on the end of Swankie's assist and found the bottom corner with a neat strike.
Alistair Brown, Hunter, McCann, John Robertson (Twaddle 64), Brownlie, Sinclair, McGowan, Crawford, Moffat, Winters (Ross Robertson 66), Marenghi (Shankland 70). Subs Not Used: Martin, Roberts.
McGowan, John Robertson.
Soutar, McCulloch, Iain Campbell, Bolochoweckyj, Tulloch, Templeman (Sellars 86), Ross Campbell (Motion 80), Fotheringham, Swankie, Graham Gibson, Denholm (Kader 74). Subs Not Used: Scott, Dunlop.
Iain Campbell 45 pen, Swankie 59, Fotheringham 89.