Reigning Olympic champion Adams had come out on top in their last nine encounters but Beijing bronze medallist Ostapchuk produced launched a third-round throw of 21.36 metres to claim her country's first athletics gold of the Games.
Adams, who beat Ostapchuk to the top of the podium at last year's world championships, could manage only 20.70 metres in her third round and looked tearful at the end as Ostapchuk set off on her victory lap of honour.
Russia's Evgeniia Kolodko produced a personal best of 20.48 metres on her sixth throw to snatch the bronze from China's Lijiao Gong.
"I'm very happy at this moment," Ostapchuk told reporters.
"It's my third Olympic Games and it's a long way to get to this gold medal."
Adams said she had just "not felt right".
"It just didn't come together," she told reporters. "I put my heart out there trying... it's life, it's sport. It's her day you know, good for her.
"I'm very disappointed with how it was but I'm happy with winning a medal for New Zealand."