RIO DE JANEIRO – Masato Sakai claimed silver after coming out of nowhere to almost deny Michael Phelps his 20th Olympic gold medal in the men’s 200-meter butterfly at the Rio Games on Tuesday.

There was nothing Japan could do to stop Phelps from collecting his 21st either, as the most decorated Olympian of all time dried himself off and joined his United States teammates just over an hour later to win gold in the 4×200-meter freestyle relay.

The Japan team of Kosuke Hagino, Naito Ehara, Yuki Kobori and Takeshi Matsuda took the bronze, the country’s first medal in the event since the 1964 Tokyo Olympics.

“Doing a double like that is a lot harder now than what it once was, that’s for sure,” said the 31-year-old Phelps. “Even with an hour, that was a challenging one tonight. I’m looking forward to the rest of the week and I’m not even half done yet.”

Sakai, who trailed in sixth going into the final 50 meters of the 200 butterfly, made an extraordinary late push to finish 0.04 seconds behind Phelps in a time of 1 minute, 53.40 seconds. Sakai came home ahead of Hungary’s Tamas Kenderesi (1:53.62) and defending champion Chad le Clos of South Africa (1:54.06), while Daiya Seto was fifth in a time of 1:54.82.

“I saw the red lamp come on when I touched the wall but I didn’t know which position I finished in,” said the 21-year-old Sakai. “I didn’t think I was going to be second. I just feel so happy right now.

“I had been working on my performance over the final 50 meters in training camp in Mexico, so I’m really happy that it paid off.”

The race had been billed as a grudge match between Phelps and his London Olympic conqueror Le Clos, but instead it was Sakai who posed the biggest threat with a final-50-meter time that was almost a full second faster than Phelps’.

“It’s frustrating to miss out on the gold medal but when you look at it on TV, just swimming alongside one of my heroes is such an honor,” said Sakai.

“It’s still too early, but in the future I want people to think of me when they talk about the butterfly. Of course I’m aiming for the gold medal in Tokyo and I’ll be working toward that straight away.”

Phelps had a more comfortable race in the 4×200 relay later in the evening, inheriting a substantial lead from teammates Conor Dwyer, Townley Haas and Ryan Lochte to anchor the U.S. to victory in 7 minutes, 0.66 seconds.

But Japan joined the winners on the podium after edging out Australia for bronze in a time of 7:03.50, narrowly missing out on silver 0.37 seconds behind Britain.

“I could see James Guy of Britain, and whatever the result, I didn’t want this to be a negative race so I went for it from the start,” said the 32-year-old Matsuda, who swam the anchor leg in what will be his fourth and final Olympics.

“Japan is a strong swimming country but we don’t win in freestyle, so now we can say we are a major power. The other three members of this team will definitely be at the Tokyo Olympics, so I want them to aim for gold there.”

Phelps claimed his 25th Olympic medal overall from a career spanning five Summer Games, and the living legend admits he has surprised even himself.

“That’s a lot of medals,” said Phelps. “We’ve got a lot of medals. It’s insane. It’s mind-boggling to me to think about when this started.”

Elsewhere in the pool, Katie Ledecky of the U.S. came out on top of her clash of the titans with Sweden’s Sarah Sjostrom, winning the women’s 200 freestyle final in 1:53.73.

“I did come pretty close to throwing up,” said Ledecky, who won her second gold medal of the Rio Games. “It was a burp with 25 to go, but I’ve been in that position plenty of times before in practice and I knew I could accelerate to the wall.”

Sjostrom, who set a new world record in the 100 butterfly earlier in the week, completed the race in 1:54.08, ahead of Emma McKeon of Australia (1:54.92).

Hungary’s Katinka Hosszu landed her third gold with victory in the women’s 400 individual medley, beating Madeline Dirado of the U.S. (4:31.15) and Mireia Belmonte Garcia of Spain in (4:32.39) a new world-record time of 4:26.36.

“Coming to Rio, I didn’t have any Olympic medals so I would have been OK grabbing any color of medal,” said Hosszu. “If I have three golds, it’s pretty unreal. I’m super excited.”