Bottom dogs Berwick boosted their hopes of beating the drop following last week's win over leaders Brechin with another super show at Somerset Park.
Gordon Connelly hit the only goal after 34 minutes, smashing the ball home from 12 yards after a David Murie free-kick was only half cleared by home defender Barry McLaughlin.
Berwick were the better team earlier on, and Grant McNicoll and Mark Cowan both had efforts surperbly saved by home keeper Ludovic Roy.
Ayr's best effort of the first half came when a Scott Chaplain shot was parried by Gary O'Connor and Gareth Wardlaw's header was turned past the post by the keeper.
Ayr began the second half with purpose and should have equalised after 55 minutes when Wardlaw ran on to a pass from Stuart McGrady, but failed to score with only O'Connor to beat.
Ayr mounted a late rally and Scott McCulloch had a header cleared off the line by Cowan. With five minutes to go, Ayr veteran Tommy Tait headed just over following a cross from Craig Conway.
Ayr's last chance fell to teenage substitute Andy Reid, but his shot on the turn was saved by O'Connor.