Flanker Blair Cowan, fullback Stuart Hogg, centre Alex Dunbar, prop Geoff Cross and wing Tommy Seymour scored the tries and scrumhalf Greig Laidlaw kicked 12 points as Scotland avenged a 21-15 defeat by the Pacific Islanders two years ago.
Flyhalf Latiume Fosita converted four penalties, punishing Scottish maul infringements, for Tonga who led 12-7 after half an hour but Hogg's breakaway try gave the home side a 14-12 halftime lead.
Both sides had a player sinbinned, Tonga flanker Nili Latu and Scotland's Dunbar, in the first half of the match played on Kilmarnock FC's artificial Rugby Park pitch.
Scotland began the test window with a 41-31 win over Argentina before losing to New Zealand 24-16 last weekend.