Serena Williams was playing just her sixth match after a 11-month lay-off which started after she retired injured at Wimbledon in July 2021
Williams, ranked 605th and turning 41 next month, won 7-6 (7-4) 2-6 6-2 to stun the Estonian in New York.
The American recently announced her intention to retire after her home major and is now into the third round.
Williams will play Australia's Ajla Tomljanovic next on Friday.
A few weeks ago, Williams announced she was "evolving away" from playing tennis in an essay for fashion magazine Vogue, but agreed after beating Montenegro's Danka Kovinic on Monday she had been vague about her exact timeline.
"There is no rush here," she laughed after beating Kontaveit. "There is still a little left in me."
While lacking some of the pomp and ceremony from her opening match on Monday, this was another special atmosphere as 23-time major singles champion Williams looked to extend her storied career by at least another round.
More A-List celebrities, including golf superstar Tiger Woods, actress Zendaya and soul singer Gladys Knight, were among an adoring home crowd on the cavernous Arthur Ashe Stadium which was wowed by Williams winning a tense opening set.
The former long-time world number one suffered a dip of energy from the start of the second set as Kontaveit levelled but she recovered to win an edgy decider.
In the end, Williams handled the occasion better than her 26-year-old opponent - who looked emotional before the final game as she hid under her towel - and secured a victory that left many in an exultant crowd jumping to their feet to celebrate.
"I'm a pretty good player, this is what I do best. I love a challenge and I'm rising to the challenge," said the six-time US Open champion, who first won at Flushing Meadows in 1999.
"I haven't played many matches but I've been practising really well. Now it's coming together in New York."
Whether it would come together in New York was debatable heading into the Grand Slam tournament.
Williams had only played four times since making her return from an 11-month injury lay-off, with her most recent match ending in a thrashing by British number one Emma Raducanu in Cincinnati.
There she had struggled with a knee injury in the build-up. Here she is fit, moving well and matching the athleticism of her younger opponents.
One factor which could never be questioned is her insatiable desire to win and the ability to summon the mental strength to overcome adversity.
Asked if she was surprised by her level, Williams replied: "No. I'm just Serena."
Kontaveit is ranked second in the world but has struggled to live up to her status in recent months.
Her level was decent against Williams in their first career meeting and she said she thought she "didn't play a bad match at all".
"I think you have to be ready for really great tennis because Serena has been such a big champion, winning all these Grand Slam titles for a reason," she added.
"She definitely raised her level in the third set. She played amazing."
Golfer Tiger Woods sat among Williams' team and family in her support box, with Williams saying afterwards her friend's motivating chats were "one of the main reasons" she was still playing
The atmosphere on Ashe lacked the same fervour as on Monday and felt tense in the opening stages, perhaps because there was less expectation on Williams' chances because of Kontaveit's seeding.
But it soon became apparent that Williams was going to push Kontaveit hard.
"I'm just pleased I showed up because the last few tournaments I didn't show up," said Williams.
The world number two fought off three break points to hold for 4-3 after a game that lasted more than 11 minutes and faced another in her next service game.
The crowd was ready to be ignited and an explosion of noise arrived when Kontaveit hit a return long to give a 5-3 lead to Williams.
Now serving for the set, Williams threw in her worst game of the match at the worst possible time.
A double fault handed the break straight back to Kontaveit and the pair both held serve again to ensure the opener would be decided by a tie-break.
Williams claimed a mini-break when a Kontaveit drop-shot floated into the net and served out the set with an ace, leading to more passionate appreciation.
There was an drop in energy from Williams at the start of the second set as Kontaveit raced 3-0 ahead with a double break.
After errors contributed heavily to Williams clawing one of them back, Kontaveit reasserted her authority to quickly level the match and the veteran disappeared at the end of the set for an extended breather backstage.
Looking revived on her return - which she joked was down to "being lighter" after a toilet break - Williams broke Kontaveit's serve at the third opportunity for a 2-0 lead.
Going on to record a straightforward victory always felt unlikely amid the tension and more swings of momentum came as the pair swapped breaks in consecutive games.
When Williams held for 4-1, the mood of the crowd indicated they finally truly believed she would complete victory and she did that with a backhand winner after a nervous game from Kontaveit.
-- Courtesy of BBC Sport