RIO DE JANEIRO — On a Sunday night of sensational performances at the Olympic Aquatics Stadium, two Marylanders showed why they're the greatest stars in swimming.

First, Katie Ledecky smashed her own world record in a virtuoso 400-meter freestyle victory. Then Michael Phelps reminded everyone why he's the best ever, giving the United States a lead it would never relinquish with a scorching leg in the 4x100-meter freestyle relay.

The relay victory was the more unexpected of the two and Phelps' performance was the more surprising, though perhaps it shouldn't have been. It was not even certain he would be on the relay team until the day of the race.

But he earned his record 19th Olympic gold medal and 23rd overall Olympic medal with a 47.12-second split. Swimming in his fifth Olympics, Phelps has repeatedly said he's in love with his sport again. And on this night, that love translated to speed that would have made his younger self proud.

Those who'd paid attention the past four years were not surprised by what Ledecky did.

She'd built to this practice by practice, race by race, record by record.

But for those who watch world-class swimming only on a four-year cycle, the 19-year-old from Bethesda offered a Sunday revelation in her first individual final of these Olympics.

Ledecky left the rest of the field far in her wake in the 400-meter freestyle, winning her second of an expected five medals at these Games and shattering her own world record by almost two seconds in the process.

“Pure happiness,” she said when asked what she felt as she looked up at her winning time of 3 minutes, 56.46 seconds, which beat Great Britain's Jazz Carlin by almost 5 seconds. American Leah Smith took the bronze medal.

Ledecky was the most dominant swimmer in the pool, even on a night when Phelps — born in Baltimore and raised in Rodgers Forge — made his sensational Rio debut.

And the thing is, nothing Ledecky did was all that unusual for her. She had been plotting to swim the event in 3 minutes, 56 seconds (only one other woman has ever broken 4 minutes) since 2013.

Like Phelps in his prime, Ledecky seems immune to off nights in the biggest races. She has never lost a major individual final in international competition, in part because “she doesn't care” about the size of the stage, in the words of her coach, Bruce Gemmell.

She speaks of world championships and old high school meets with the same enthusiasm.

Inside the world of swimming, Ledecky's dominance has been a source of awe for three years now. Friends, coaches and competitors ran out of new ways to describe her greatness long ago.

Going into Sunday night's final, she owned nine of the 10 best times in history in the 400 freestyle and the 10 best times ever in the 800 freestyle. More recently, she's become the best in the world at 200 meters. And as she demonstrated in her silver-medal relay swims on the first day of competition here, the 100 meters might be her next horizon to conquer.

No swimmer has ever been so good across such a range of distances.

But to many casual Olympic viewers, Ledecky was probably still the 15-year-old who came out of nowhere to win a gold medal in 2012. Sunday night was a chance to show off her evolution to a global audience.

Not that you'd ever catch Ledecky caring about that sort of thing. Her public comments are as consistent as her racing performances.

She's always striving to lower her times. She swims hard whenever she mounts a starting block. And she loves representing her country. That's about all you're ever going to get out of her, even though she's a bright woman headed to Stanford after the Olympics.

“She races,” said her U.S. teammate, Simone Manuel. “She's a racer.”

Ledecky had finished the 4x100 relay about 15 hours before her 400 freestyle preliminary on Sunday afternoon. She seemed to cruise through the first 200 meters of the qualifying race, taking a lead but well behind her world-record pace.

But then she kicked up her stroke and started gaining on her own history, the thing she's truly chasing every time she jumps into the pool.

She came up just short after what she described as a “lackadaisical” final stroke. Still, it was the second fastest 400 freestyle any woman had ever swum, and she did it almost casually.

“That's the easiest I've ever gone under four minutes,” she said matter of factly.

It turned out she and Gemmell had planned an easy pace in the first half of the race. He didn't want Ledecky carrying her stroke from the previous night's sprint into the longer swim.

“I think it bodes well for tonight,” she said. She wasn't wrong.

Phelps will begin his individual schedule today with a preliminary heat and evening semifinal in the 200-meter butterfly.

But relays have long been important to his story.

He built the entire first half of his career toward Beijing in 2008, where he planned to break Mark Spitz's record of seven gold medals at one Olympics.

But for Phelps to pull it off, the Americans needed to win the 4x100 freestyle relay against ferocious competition from the French and the Australians.

Phelps set an American record for the 100 freestyle on the opening leg, but the U.S. lost its lead on the third leg, and anchor Jason Lezak was a body length behind Alain Bernard of France as they turned for the final 50 meters.

Over that span, Lezak pulled off what might have been the greatest rally in Olympic history and touched the wall just ahead of Bernard.

Phelps unleashed a wild bellow, clenching both fists. It's still a strong candidate for the most dramatic race of his career.

He ultimately eclipsed Spitz when the Americans won gold in the 4x100 medley relay, an event they've always dominated.

But in recent years, American relay teams have faltered. The U.S. men didn't even qualify for the final in the 4x100 freestyle at world championships last year.

Phelps has not hidden his distress at this state of affairs.

He did not swim the 100-meter freestyle at the Olympic trials to establish a time that would clearly put him on the relay team here. But he gave hints he'd like to participate.

The decision lay with his coach, Bob Bowman, who's also the coach of the U.S. men's team in Rio. And Bowman ultimately put Phelps on the second leg, with Caeleb Dressel leading off, Ryan Held swimming the third leg and Nathan Adrian anchoring.

Phelps fully justified the choice, helping the U.S. reclaim its former glory and adding another gem to his relay collection.

childs.walker@baltsun.com

twitter.com/ChildsWalker