Sharapova, competing for the first time since retiring from her first-round match at Wimbledon, appeared to be on course for just a fourth match win since January when she went up a set and an early break on the 16th seed from Estonia.
Having forced the third set, Kontaveit gave herself a chance to serve for the match with a break of serve in an epic ninth game. Sharapova hung on through nine deuces before Kontaveit converted her third break chance in a game that lasted more than 15 minutes.
"I was just trying to take it point by point and not think about the score that much. It worked in the end," said Kontaveit, who converted her first match point in the following game when Sharapova sent a service return long.
While Kontaveit readies herself for a second round match against either Venus Williams or Carla Suarez Navarro -- who open play on Centre Court on Tuesday -- Sharapova will set her sights on next week's tournament in Cincinnati, where she has received a wild card just as she did in Toronto.
"I don't think this is the time to take a break," she said.
The 32-year-old has slipped to 82nd in the world rankings after another season marred by injury. She had missed more than four months in the wake of right shoulder surgery when she returned for the grass court season this year.
She was forced out of Wimbledon by a left forearm injury.
Sharapova said Monday's physical battle showed she'd made progress since Wimbledon.
"I put a lot of work in to get to this stage, so I think to finish off this match is good," she said. "Definitely not the result I would have liked, but overall feeling pretty good about it.
"I'm still building the confidence and my form and that's something that's just going to come with time and with match play," she added. "Unfortunately, I just haven't had that yet, so will just hopefully try to build on it."
- Kasatkina tops Kerber -
The top eight seeds in the key US Open tuneup receive first round byes -- a group led by world number one Ash Barty of Australia which also includes No. 2 Naomi Osaka of Japan, fourth-seeded Wimbledon champion Simona Halep and eighth-seeded Serena Williams.
German 12th seed Angelique Kerber was unable to make to the second round, however, the three-time Grand Slam champion beaten 0-6, 6-2, 6-4 by Russian Daria Kasatkina.
Two former champions made it safely into the second round, Caroline Wozniacki and Belinda Bencic both posting straight-sets wins.
Denmark's Wozniacki, seeded 15th, shook off an early break of service, rallying from 2-4 down in the opening set to win in 90 minutes.
The Dane, who lifted the WTA's Canadian Premier-level title in 2010 when the tournament was in Montreal, hasn't always thrived in the years in which Toronto hosted, although she did make it to the final in 2017.
"I'm just happy to be here and win another match here and get a good start," Wozniacki said. "We'll see how it goes.
Switzerland's Bencic, seeded 11th, advanced with ease, dispatching Russian qualifier Anastasia Potapova 6-2, 6-1.
Despite the lopsided scoreline, Bencic needed four match points to close it out.
Bencic won the second WTA title of her career in Toronto in 2015, beating four of the top-six players in the world, including Serena Williams.
But she hasn't played in Toronto since as her precocious WTA rise was stalled by a string of injuries.