Both riders tried to move away from the Manx rider on the last climb - just off George Square in the city centre - and Scotsman Millar led coming into the final stages in Glasgow Green.
But Cavendish hung in close enough to unleash his unrivalled sprinting ability in the home straight as he overtook Millar and moved away from Stannard, who recovered from a puncture in the penultimate lap of 13 lap to finish second, about eight lengths behind.
Lizzie Armitstead earlier secured an emphatic victory in the women's race as an estimated 30,000 spectators lined the 14.2km route in Glasgow's city centre and west end, which will be used for next year's Commonwealth Games.
Her second triumph in the competition was anticipated but Cavendish feared the collective threat of his former Team Sky colleagues Stannard and Peter Kennaugh, who was in the four-man leading group until the very late stages. However, they could not engineer a breakaway.
The Omega Pharma Quickstep rider said: "My form's good and I have trained well because the Tour de France is coming up but to be honest it's a bit unexpected that I won here.
"I was here more for, one, as preparation for the tour and, two, to see the course for the Commonwealth Games next year.
"Normally with so many Team Sky riders it's going to be difficult to win here so I wasn't really expecting it.
"But we got a good group away after about 20 kilometres, rode well together and I'm happy, I had a bit of luck in the end when Ian was left isolated."
The 28-year-old added: "I'm patriotic, I'm proud to be British, so I'll be proud to wear the jersey that represents my country in France next week."
Stannard praised Cavendish's class after his former team-mate allowed him to catch up just before the end of the penultimate lap, shortly after his puncture.
"Cav got them to wait so I'm really appreciative of that good sportsmanship," he said.
"It was the kind of circuit he could hang in on. If the climbs were 100 metres longer then it would have been different. But then again it's great to see Cav have the jersey.
"He raced really aggressively. People think he's just a sprinter but he's a world-class bike rider."
Armitstead followed up her silver medal in the time trial event earlier this week as she finished 63 seconds ahead of Wiggle Honda pair Laura Trott and Dani King.
The 2011 champion, who has now finished in the top two for five years running, made her move in the penultimate of eight laps before streaking clear in the final stages.
The 24-year-old Boels Dolman rider said: "It's really special. It was one of my main goals of the season.
"I've had an up-and-down season so far so I needed a bit of a confidence boost and hopefully having the jersey on my back will help."
Armitstead added: "I've got a lot of experience on the road now and it's their first real season on the road so I felt confident."
Trott, who claimed the under-23 title, edged King in a sprint finish but admitted Armitstead was the "stronger and better rider on the day".
And King added: "I am really happy. A couple of days ago I didn't feel great after the time trial so if someone said to me you were going to get third today [Sunday], I would have been over the moon.
"We worked well together, did everything we could and Lizzie was the better rider today [Sunday]. She won a silver in the Olympic Games in the road race so I don't think we can complain."