After crashing in Sunday's opening stage in Norfolk and being beaten to the line by Leigh Howard on stage two, the world champion got it right at the third time of asking.
The Isle of Man speedster was given a superb lead-out by Bernhard Eisel and Luke Rowe to coast to a stage success in the Scottish market town for a second year in succession.
Cavendish said: "I’m delighted. We tried a few different things yesterday which didn’t quite work out, so [Sports Director] Servais Knaven told us to keep things simple today and go for the sprint. We’ve got the team here who can do a brilliant lead out and it was pretty straightforward in the end.
"There’s only six riders per team here so the guys had to do long pulls. Bernie did almost a one-kilometre turn and then Luke went with just under 1km to go – which is far longer than the usual 400m for a lead-out man – and he rode it perfectly into the last corner.
"I knew the finish, that it would have a tailwind going downhill, so that meant I could go early, and I’m really happy to get the win."
Howard was a distant second ahead of Orica-GreenEDGE team-mate Aidis Kruopis but the Australian took the overall race lead from Boy Van Poppel.
Ireland's Peter Hawkins (IG Sigma Sport), Bernard Sulzberger (Raleigh-GAC), Wesley Kreder (Vacansoleil-DCM) and the British duo of Kristian House (Rapha Condor) and Peter Williams (Node4-Giordana) formed the break of the day on the 152.6km stage from Jedburgh.
They formed before the category one climb of Roberton after 22km and built up a maximum lead of four minutes.
But UnitedHealthcare led the peloton to reduce the deficit to 1:20 as the leaders passed under the finish line in Dumfries with 30.5km to go.
House, Williams and Sulzberger were caught with 22km left on the finishing circuit but Kreder and Hawkins persisted although the Irishman was then reeled in.
Sep Vanmarcke bridged the gap to Kreder but Team Sky were on the front of the peloton and the duo saw their bid for a stage win foiled with 2.5km remaining.
The eight-stage Tour of Britain continues on Wednesday with a stage from Carlisle to Blackpool.
- Luke Rowe