A double from Greg Stewart kept Cowdenbeath’s survival hopes alive and left United with an uphill battle to reach the play-off final.
The Blue Brazil dominated the opening exchanges and deservedly opened up a two-goal advantage.
However, Gordon Pope’s late strike has given Ayr some home going into the return leg at Central Park on Saturday.
The visitors dominated possession early on without creating many chances, while the home side carved out a number of good opportunities they weren’t able to take.
Just 15 minutes in, some good play from Cowdenbeath ended with Lewis Milne playing the ball across the face of goal for Greg Stewart to fire into the back of the net.
Alan Lithgow then failed to control a long ball, but Kane Hemmings’ shot went straight to the keeper.
Another mistake allowed Stewart into the box and he went past Lithgow before firing a low shot that David Hutton held.
Then 10 minutes before the break, Stewart doubled the lead with a fantastic curled effort into the top corner.
Pope had the home fans out of their seats with a 30-yard drive on the stroke of half-time, but it flew wide.
Then, 10 minutes after the break, Rory McKeown missed the chance to put Cowdenbeath three up when he smashed a loose ball against the crossbar.
Kevin Kyle,who came on for Ayr after 60 minutes, got on the end of an Adam Hunter cross but was not able to steer it away from Thomas Flynn.
Hemmings responded with some nice footwork in the box before he smashed a shot at goal, which Hutton parried.
The home side pulled a goal back 10 minutes from time when a corner fell to Pope, who took a touch before stroking the ball into the far corner.
Cowdenbeath responded with their own corner routine as Stewart played it to McKeown, who drilled a 25-yard strike just wide of the bottom corner.
Attendance: 1,495.