Russia edged out Japan for the men’s gymnastics team gold.

TOKYO — The thud of Daiki Hashimoto’s dismount echoed through Ariake Gymnastics Center after a long night of the Olympic gymnastics men’s team final.

He stuck the landing and did all he could to make his team win. He waved to the smattering of fans in the arena, as well as the many Japanese volunteers, to coax them to their feet, as his admirers leapt and cheered back at him.

But their joy was put on pause. Hashimoto, the teenage Japanese star, and his team needed to wait for the score from the final Russian gymnast to be posted on the leaderboard before they could celebrate. In the end, to their dismay, they would not be celebrating at all.

Nikita Nagornyy of Russia ruined it for the home team, tumbling and twisting as well as he could on the floor exercise — in fact better than he had planned because he added extra tumbling — and his score was enough to eke out the win. Russia claimed the Olympic gold medal, unseating the 2016 Olympic champions, Japan, by finishing with 262.397 points. Japan was second, just 0.103 points behind. China was third. The United States team finished fifth to match its previous two Olympic finishes.

Once the final scores were posted, the Russian gymnasts fell to the ground in exhilaration and relief, while some Japanese gymnasts buried their head in their hands and others stood frozen, stunned by the unexpected loss. There were tears all around.