Ostapenko took an injury timeout to have her left thigh strapped after dropping the first set, then won six out of seven games to force a deciding set at Margaret Court Arena.
However, in the third set, Kontaveit, the No. 32 seed, broke Ostapenko's service in the seventh game, held and then broke again in the ninth to end the match for a 6-3, 1-6, 6-3 victory at Melbourne Park.
It continued Ostapenko's poor start to the season since hiring new coach David Taylor. She lost in the first round at tournaments in Shenzhen and Sydney.
The loss by the seventh-seeded Ostapenko left only two major winners in the women's draw -- and only one of them can reach the fourth round. Five-time major winner Maria Sharapova and former Australian and US Open champion Angelique Kerber are playing each other Saturday.
Players were bothered and spectators clamored for shade and mist-spraying fans in searing heat at Melbourne Park, which had organizers on the verge of enforcing the tournament's extreme-heat policy before temperatures dropped quickly after peaking around 2 p.m. local time.
Play can be suspended at the Australian Open if the temperature 40 Celsius (104F) and a combination of factors -- including temperature, humidity and breeze -- reach an unbearable limit.
Elina Svitolina ended 15-year-old Marta Kostyuk's strong run in the Grand Slam event, meeting her at the net for a warm embrace and offering some words of encouragement after a 6-2, 6-2 victory on Rod Laver Arena.
The fourth-seeded Svitolina reached the fourth round at the season-opening major for the first time.
"It was sad playing another Ukrainian girl, same country is always tough," said Svitolina, one of five women in contention for the No. 1 ranking. "She's a great fighter. She has a great future -- we're going to hear a lot more about her."
Kostyuk entered the tournament ranked No. 521 -- a number that will likely be halved -- and had wins over 25th-seeded Peng Shuai and Olivia Rogowska to become the youngest player to win main-draw matches at the Australian Open since Martina Hingis in 1996.
She had nine double faults against Svitolina, including on match point, and got only 37 percent of her first serves into play.
Svitolina, the only seeded player still in contention in her quarter, had five aces and only 11 unforced errors and didn't serve a double fault in the 59-minute match.
Kostyuk sobbed into a towel in the tunnel soon after leaving the court, but could joke about the defeat when asked later what she could take out of the experience.
"Well, a lot," she said. "How much you have to pay Svitolina to have one-hour lesson? I got it for free."
Kostyuk received entry into qualifying because of her junior girls' victory last year at the Australian Open. She won all three qualifying matches, then her first two in the main draw.
Alize Cornet, who needed a medical timeout and a doctor to take her blood pressure as she struggled with heat stress in her 7-5, 6-4 second-round loss to Elise Mertens, was among those suggesting the extreme-heat policy needs reviewing.
"I started to feel dizzy. ... I was feeling super, super hot. I kind of felt that I could faint at any moment," she said, adding that while precautions were taken by tournament officials, "playing in this condition is of course very dangerous for the health of the player.
"The limit of not playing the match is really high. ... I think this limit should be a little bit lower."
After saving two match points and trailing 5-1 in the third set in her last match, there was no real drama for Caroline Wozniacki in her third-round win over Kiki Bertens. The No. 2 seed won 6-4, 6-3 to advance to a fourth-round match against No. 19 Magdalena Rybarikova.
Wozniacki had to save four break points while serving for the match Friday, but she clinched it on her fourth match point when Bertens' return of serve went long.
The former No. 1 Wozniacki is one of four players here who could overtake top-seeded Simona Halep for the No. 1 ranking at the end of the Australian Open.
"That was really ugly," Martic said of the heat. "We were lucky to play on Rod Laver because we had some shade behind so you could hide for a few seconds in between the points.
"Other than that, it's just, you just need to be mentally tough and ready to just suffer out there."
Martic with meet Mertens in the next round.
The Associated Press contributed to this report.