Inspirational targetman Gavin Swankie blasted the Loons into play-off contention on Tuesday night with his brilliant brace helping them close the gap on the Honest Men.
The hard-fought victory left Forfar just four points behind United, with a game in hand as the battle intensifies for a top four place.
Later proud boss Dick Campbell hailed Swankie and veteran former Scotland goalkeeper Rab Douglas, whose acrobatic save from a Kevin Kyle early in the second half helped pave the way for victory.
The gaffer said afterwards: “At this stage of the season it’s not about how you play it’s all about accruing points. I am delighted to come to Somerset Park and win, especially since Ayr have been doing well. It was a world class goal from Swankie, he took it well and it was a fantastic save in the second half from Rab Douglas, who still has so much enthusiasm for the game. We have been in four playoffs in the last five years and are now just four points behind Ayr with a game in hand.”
The Loons began strongly and in three minutes an Iain Campbell shot from outside the box was well saved by home goalie David Hutton.
Three minutes later Mark Baxter headed the ball back to Douglas to keep Michael Donald at bay.
In 12 minutes the visitors capitalised on their dominance with a vintage three-man move which carved open the home defence giving them the lead. Ross Campbell made a darting run and squared to David Hilton who set up Swankie to skilfully sidefoot home from 10 yards.
Back at the other end a minute later a long range Craig Malcolm shot was confidently saved by Douglas. Michael McGowan then had a shot from 14 yards well saved.
Douglas then showed his class by spectacularly tipping a 25-yard free-kick from Anthony Marenghi over the bar.
However in 34 minutes it was all-square as a Marenghi corner-kick was headed on by Martyn Campbell to Craig Malcolm to blast home from a tight angle from 12 yards.
Two minutes from half-time Swankie shot inches over the bar from 35 yards.
However right on the interval the Loons restored their lead as Hilton made a surging run and squared to Chris Templeman to drill home from 12 yards.
Five minutes after the break Douglas made a miraculous save from a netbound Kevin Kyle header. Then in 64 minutes parity was restored when Campbell hooked the ball home from three yards amidst a goalmouth scramble.
Only two minutes later the Loons were in front again with a great piece of skill. Jackson Longridge misjudged a clearance and Swankie sent home an exquisite chipped lob from 12 yards.
Late on Hilton and Swankie had chances to further increase the lead but they had done enough and three vital points were secured.
Forfar Athletic: Douglas; Baxter, I Campbell, Fusco, S Malcolm, Dodds, R Campbell (Kader 86); McCabe, Templeman, Swankie, Hilton. Subs not used: Hill, Fotheringham, Andrews, Dale, Malin, McCluskey.
Ayr United: Hutton; Hunter, Longridge, M Campbell, Lithgow, McLauighlin (Shankland 72); McGowan, Marenghi (Forrest 58); Malcolm, Kyle, Donald. Subs not used: Newman, Gilmour, Pope, Crawford, Roberts.