Craig Malcolm's second goal of the season secured Ayr's 3-2 win over Queen's Park 3-2 in the Scottish Cup.
The visitors took the lead in the 27th minute when James Brough got on the end of Blair Spittal's ball to nod in from the middle of the box.
Ayr hit back five minutes before the break when Anthony Marenghi fired in a free kick from 25 yards.
The Honest Men went ahead five minutes into the second half when Alan Lithgow swept the ball past Lucas Birinstinfil before Malcolm made it 3-1 with a fine strike 10 minutes later.
Scottish League Two's basement club pulled one back in the 67th minute when Spittal rifled in from the centre of the area but Ayr held on to win.