It wasn't going to be a close race as to whether the United States was going to end up with the most total medals Sunday when competition ended at the Tokyo Olympics. That was a foregone conclusion days ago.
The question was going to be whether the U.S. would edge out China for the most gold.
At about 3:15 p.m. Japan time (2:15 a.m. ET), the answer was known.
Heading into the final weekend, the U.S. trailed China by about a half-dozen in the gold medal column. But the weekend also brought a slew of wins for Team USA, some surprising, some not. The U.S. men's and women's basketball teams won gold, extending their streaks, as did the women's water polo team. On the track, both the men's and women's 4x400 relay teams easily won gold.
On Friday, wrester Gable Steveson scored on a spin-behind takedown with 10 seconds remaining, then another with less than a second left to win the men’s freestyle 125-kilogram final. That unlikely, last-second win, helped close the gap.
But China kept the pressure on. Its dominance in diving during these Olympics continued by winning the men's 10-meter platform Saturday. The Chinese also won the women's canoe double 500-meter race.
Then came a surprise on Sunday. American Jennifer Valente got up from a crash the omnium-ending points race to hang on for the gold medal -- the only gold the U.S. would win in cycling at these Games.
With the U.S. and China tied with 38 gold medals each, it came down to four events: the women's volleyball final featuring the U.S. vs. Brazil plus three boxing finals which included two Americans and one Chinese boxer. Neither country would be in any other finals after that.
Keyshawn Davis of the U.S. lost to Andy Cruz of Cuba for the men's lightweight gold medal.
Minutes later, the U.S. beat Brazil in straight sets for the women's volleyball crown, giving the U.S. its 39th gold medal and one more than China.
A short time later, Li Qian of China lost to Great Britain's Lauren Price in the women's middleweight title bout.
That clinched the most gold medals for the U.S. at the Tokyo Games. And it turned out to be the difference as Richard Torrez Jr. of the U.S. lost in the men's superheavyweight final to Bakhodir Jalolov of Uzbekistan about 30 minutes later -- the final event involving the U.S. or China in Tokyo.
The United States finished with 113 total medals: 39 gold, 41 silver and 33 bronze. The U.S. won the most of every color.
China finished second in total medals with 88, gold (38) and silver (32).
ROC, the team of Russian athletes who were not allowed to compete under the Russian flag or anthem due to a doping suspension against the country, finished with the third-most total medals (71) and second-most bronze (23).
The Associated Press contributed to this report.