Andrew Skeen gave Melrose the perfect start with two penalties in the opening seven minutes.
But, once Accies adapted to the early kick-off after the journey from Edinburgh, they denied the hosts possession and put the pressure on.
Ruaridh Bonner’s penalty cut the deficit and Dan League was driven over to give Accies the lead. But a Joe Helps try put Melrose back ahead at the break.
However, Accies started the second half strongly and Nyle Godsmark crashed over, Bonner converting.
Iain Berthinussen scored Accies’ third try but Melrose hit back with a try by Alun Walker. Skeen converted and when he cut the gap to one point with his third penalty it was game on.
A foul by Graeme Dodds saw him sent to the sin bin, but Bonner missed an easy penalty.
Accies had to defend desperately in the final minutes, but no one could deny the visitors the points.