The home side started at pace and after 10 minutes they were 12-0 up thanks to tries from front-row men Nick Cox and Hayden Wisnewski.
A third try by centre Dean Kelbrick then made it 17-0 after 26 minutes and it seemed like it was going to be a pretty one-sided afternoon.
A penalty by centre Andrew Skeen and a converted penalty try did get Melrose into things before the interval to leave them 17-10 down at the break.
In the second half, Ayr's points came from tries by winger Craig Gossman and captain Calum Forrester, while stand-off Finn Russell kicked five points.
Melrose got another penalty try and one through back-row John Dalziel, with Skeen kicking two further conversions, but it was not enough for them to save the match as Ayr came out on top 32-24.
At Raeburn Place two converted tries in the closing minutes before half time acted as a springboard for Heriot's to win 21-15 against Edinburgh Accies.
The two sides were evenly matched over the first 35 minutes before Heriot's hooker Kevin Bryce bustled his way over. That score was followed by a try from back-row Chris Mulligan, with scrum-half Graham Wilson converting both. When Heriot's added a third try through winger Colin Goudie five minutes after the break they were 21-0 to the good and looking fairly comfortable.
The home side fought to get themselves back into the match with tries from winger Alex Blair and replacement Andrew Findlater, as well as five points from the boot of centre Ruairidh Bonner.
However, they failed to add to their tally and Heriot's held on to leapfrog their opponents into fifth place in the table, and leave them challenging for a B & I Cup spot.
Aberdeen Grammar lost out 28-27 in a ding-dong encounter with Stirling County at Rubislaw.
In the first half, County scored three converted tries through centre Mark Bennett and two from back-rower Steve Swindall, with stand-off Stuart Edwards adding the extras.
Grammar only had five points at the break, courtesy of a Steve Aitken try, but they came out flying in the second 40 minutes and scored two tries through back-row Cam Eyre, plus one apiece from fellow back-row Sandy Warnock and winger Callum Anderson.
County, however, scored another try through winger Byron McGuigan, which was enough to see them to victory.