RIO DE JANEIRO — As he looked up at a boisterous crowd, triumphant for the 20th time in his unmatched Olympic career, Michael Phelps raised his hands and flicked them in his direction as if to say: “Bring on the world.”

Phelps powered past the world Tuesday night in the 200-meter butterfly to win an individual gold, then he anchored the 4×200-meter freestyle relay team to pick up his second gold.

Because he has won so relentlessly, Phelps has rarely needed to seek retribution. Hence the exquisite tension as he prepared to meet South African Chad le Clos in the 200-meter butterfly final.

Le Clos is the man who beat Phelps in the same event four years ago and also the rival who seems to irritate him most. So after Phelps won his second gold medal of these Games and vanquished le Clos, who finished fourth, he seemed to defy anyone to come and beat him.

A little more than an hour after his butterfly final, Phelps was to anchor the 4×200-meter freestyle relay, a race that didn’t even seem on his radar five weeks ago.

Just as he did Sunday night, Phelps shared the stage at the Olympic Aquatics Stadium with Katie Ledecky, the Bethesda, Md., teenager who’s primed to replace him as the world’s most dominant swimmer.

Katie Ledecky, right, dives into the pool en route to her second gold medal of the 2016 Olympics. Associated Press/David J. Phillip

Katie Ledecky, right, dives into the pool en route to her second gold medal of the 2016 Olympics. Associated Press/David J. Phillip

The 200-meter freestyle is not an event in which Ledecky overwhelms. She’s still relatively new to being a world-class sprinter and was considered a co-favorite with Sarah Sjostrom of Sweden.

But Ledecky showed she’s just as good in a dogfight as she is when swimming away from the field, winning her second gold medal of the Games in 1 minute, 53.73 seconds. Sjostrom pushed her hard over the last 50 meters and won silver in 1 minute, 54.08 seconds.

The 200 butterfly was more than Phelps’ first individual final of these 2016 Games. It was a chance for him to wipe away one of his few Olympic disappointments.

Four years ago, he sought his third consecutive gold medal in the event, the same one in which he qualified for his first Olympics at age 15 and the same one in which he lowered his own world record seven times between 2001 and 2009.

But an undertrained and unhappy Phelps did not account for a late surge from le Clos, the confident young South African who wanted to be, well, the next Michael Phelps.

The possibility of a Rio rematch has intrigued the swimming world ever since.

The story became that much richer with the late-career improvement of Hungarian Laszlo Cseh, a five-time Olympic medalist who has never managed to beat Phelps in the biggest races but who came in with the fastest time of 2016. And then another Hungarian, Tamas Kenderesi, asserted himself by swimming the fastest semifinal time.

In the end, neither le Clos nor Cseh threatened him. Masato Sakai of Japan, yet another swimmer who grew up watching Phelps on television, won the silver medal, just .04 seconds behind. Phelps’ time of 1 minute, 53.36 seconds was slower than his world-best time of 2015, but that hardly seemed to matter.

In a twist few had contemplated coming into the games, Bob Bowman, Phelps’ and the U.S. men’s coach, added Phelps to the 4×200 freestyle relay, scheduled to start about 70 minutes after the 200 butterfly.

The decision indicated Phelps felt bullish about both his fitness and his freestyle stroke.

He did not swim a 100 or 200 freestyle at the Olympic trials, so it wasn’t clear if he would compete in either freestyle relay in Rio.

But Phelps ironed out his stroke — which had been iffy since he came out of retirement in 2014 — at pre-Olympic training camps in San Antonio and Atlanta. He swam so impressively in a time trial a week before the Olympics that Bowman put him on the 4×100 team, a decision Phelps more than justified with his race-altering relay leg Sunday night.

The 4×200 relay raised different questions, however. Not only would it be a longer swim, it would come on the heels of the highly competitive butterfly final. Such a double was no big deal to the Phelps of eight years ago, but now his 31-year-old body does not recover as quickly.

On the other hand, Phelps at his peak was one of the greatest 200 freestylers in history. And he could go all-out Tuesday, knowing he only has to swim two qualifying heats in the 200 individual medley today.

Regardless of the exact calculations, Phelps’ entry in the relay added zest to a night that was already one of the highlights of his week because of his butterfly rivalry with le Clos and Cseh.

Phelps-le Clos achieved meme status Monday night when NBC broadcast footage of Phelps glowering in the waiting room before their semifinal as le Clos bopped around with a grin on his face.

It screamed boxing movie more than swim meet, right down to the hooded robe that cast a shadow over Phelps’ grim countenance.

Beyond spurring a cascade of PhelpsFace hashtags, the scene spoke to the real differences that have made Phelps-le Clos a compelling rivalry.

The South African grew up hoping to emulate Phelps as a swimmer, then beat him in the 200 butterfly in London.

That race has stuck in Phelps’ craw, and le Clos has periodically fanned the flames by talking trash in the years since. The swimming world was titillated last summer when le Clos took shots at Phelps after laying down a world-best time in the 100 butterfly. Phelps came back later the same day with a faster swim.

Phelps was asked about the video of him and le Clos in the waiting room.

“Everybody has their own race strategy and what they do, and if that’s his, that’s his,” he said. “I honestly was trying to focus on what the guys in the heat before me were going and tried to not really even pay attention. He had a tough double tonight, some decent swims. (Tuesday’s) race I would expect will get a lot of hype.”

Note that one of those “decent swims” he alluded to was le Clos’ silver-medal performance in the 200 freestyle. So Phelps was in no mood to give le Clos too much credit.