Andreescu was up 3-1 in the first set when Williams called for a medical timeout.
Less than a minute later, the chair umpire announced that the 37-year-old Williams was retiring from the match, handing Andreescu her second WTA Premier title of the season.
The tournament's final lasted only 16 minutes.
After the chair umpire announced the retirement, Williams started to cry on her bench. Andreescu went over to comfort her, hugging her and telling Williams how much she admires the 23-time Grand Slam winner.
"I'm not a crier, but, thank you guys," said Williams as she choked back tears after accepting the second-place check. "I'm sorry I couldn't do it today. I tried but I just couldn't do it."
Williams' retirement was the last of several high-profile injuries at the Rogers Cup. Fourth-seeded Simona Halep withdrew from her quarterfinal matchup with Marie Bouzkova. On the men's side, Milos Raonic retired after two sets against Felix Auger-Aliassime in a much-anticipated all-Canadian matchup. No. 16 seed Gael Monfils then withdrew before his semifinal against world No. 1 Rafael Nadal.
The 19-year-old Andreescu, from nearby Mississauga, has victories over seven of the top 10 players in the world. Her world ranking will rise from 27th to 14th on Monday. Her previous high was 22nd.
"I'm speechless right now. I'm the first Canadian who got to the finals and has won this tournament since 1969," Andreescu said after being presented with the Rogers Cup trophy in an on-court ceremony. "This been a dream come true, really.
"This week has not been easy. I've had many, many tough matches."
Andreescu returned this week from a right shoulder injury that sidelined her since the French Open in May. She won in Indian Wells in March for her first WTA Tour title.
"What I've been through the past two months has not been easy," Andreescu said when addressing fans. "I kept telling myself 'never give up.' I'm trying to look at my injury not as a setback but more of a challenge. I tried to embrace it as much as I can."
Andreescu had been on the court more than any other player at this year's Rogers Cup at 10 hours, 54 minutes heading into the match against Williams.
Faye Urban of Windsor, Ontario, beat Vancouver's Vicki Berner in the 1969 final, when the tournament was still played on clay courts and called the Canadian Open.