With Gala edging out Heriot's 11-9 at Netherdale it now means that there are just four points between the top four.
Early on in the Borders, Ayr took the lead through a try by scrum-half Murray McConnell. Hooker Todd Pearce then got Melrose level, the Australian's try converted by centre Joe Helps to put the hosts 7-5 up.
With about nine minutes to go to half time Melrose extended their advantage to 14-5, this converted try coming from No 8 Andrew Nagle.
After the interval a converted try from centre Robbie Fergusson put Ayr to within two points and then a great try by Scotland A cap James Eddie, the Glasgow Warriors' back-row, saw them go 19-14 ahead.
Helps and Ayr stand-off Ross Curle swapped penalties and with 10 minutes to go Ayr led 22-17. The clinching try for them also grabbed them a bonus point when Curle went over.
In a tight affair at Netherdale Ewan Scott kicked a penalty in the 11th minute and the game stayed at 3-0 until the interval. A try from winger Grant Somerville after the break put Gala 8-0 up before Heriot's fought back. The Edinburgh side kicked three penalties through scrum-half Graham Wilson and were 9-8 up until a late penalty by Scott saw Gala come through 11-9.
At Mansfield Park Hawick and Glasgow Hawks drew 17-17. Second-row Bruce McNeil and full-back Neil Renwick scored tries for the Greens with Renwick kicking the rest of the points.
Full-back James Gormley and winger Gavin Lowe bagged tries for Hawks, Gormley and stand-off Mike Adamson sharing the kicking points.
Edinburgh Accies did not win a game in October, but got November off to a flier, beating Aberdeen Grammar 42-26.
Winger Jamie Farndale led the way for the capital outfit, scoring two tries at Raeburn Place, while fellow winger Lee Jones and replacement forwards Duncan Morrison and Shaun Strudwick also went over. Grammar got tries through winger Erlend Oag and back-row Tony McGuinness, but they have now lost to Accies twice this term.
Bottom side Currie gave themselves hope by beating second-bottom Stirling County 27-10 at Bridgehaugh. The visitors' tries came through scrum-half Richard Snedden, replacement forward Stuart McInally and young winger Ruairidh Smith with stand-off George Horne kicking well.
County, who have lost five in a row in all competitions, got a try through stand-off Stuart Edwards and a penalty and a conversion from centre Brian Archibald. Currie are now just three points adrift.
In the RBS National League, Stewart's Melville kept up their winning run and became the first team to defeat Boroughmuir this season, coming out on top 13-10 at Meggetland.
Selkirk stepped up their challenge for second place by beating Watsonians 18-15 at Myreside.