Home tighthead Dan Winning was yellow carded after only nine minutes but the visitors could not take advantage.
Melrose full-back Craig Jackson was off target with a 31st minute penalty but the home side were able to open the scoring in the 37th minute, second-row Angus Runciman going over from short range.
Boroughmuir were not done for the half, though, scrum-half Tom Wilson darting over,after back-row replacement Rory Drummond had gone close. Parker converted and it was 7-5 at the interval.
A well-worked try in the 47th minute put Melrose ahead 12-7, Jackson’s break from his own half setting up centre Patrick Anderson who showed good pace to go in under the posts from 40 metres out. Jackson converted.
However, at the death Matthews’ 19th try of the season and Parker’s conversion won it.