TOKYO — Katie Ledecky has taken down legends, held off would-be challengers and ruthlessly lapped some of the top swimmers in the world during an Olympic career that has taken her from London to Rio de Janeiro and now to Tokyo. In rewriting the freestyle record book, she had taken on all comers, in four individual Olympic swims entering Monday, and left them all in her wake.

But Ledecky had never faced anything like the young woman who awaited in the lane to her right at Tokyo Aquatics Centre in the final of the women’s 400-meter freestyle Monday morning. Ariarne Titmus wouldn’t stop coming. She wouldn’t wilt. She took the best Ledecky could give, and she passed her and beat her.

In the most anticipated four minutes of swimming in recent Olympic history, Ledecky vs. Titmus somehow lived up to the massive, transpacific hype. Titmus, the 20-year-old Australian sensation, caught Ledecky near the 300-meter mark and held off the defending champ’s late charge in the final 25 meters, winning the gold medal in 3 minutes 56.69 seconds and becoming the first woman to beat Ledecky in an individual Olympic final.

Ledecky, 24, finished in 3:57.36, her best 400 free time since she set the world record of 3:56.46 at the 2016 Rio de Janeiro Olympics — the type of performance, frankly, many were questioning whether she still had in her — and it wasn’t enough. She settled for the silver medal, with Li Bingjie of China (4:01.08) a distant bronze.

“Certainly a tough race,” Ledecky said. “I think we delivered. You can’t get much better than that. Tremendous race, a lot of fun. I can’t be too disappointed with that. That was my second-best swim ever [in the 400]. I felt like I fought tooth and nail, and that’s all you can ask for.”

After touching the wall and checking the scoreboard, Ledecky moved in to congratulate Titmus, though the latter, overcome with emotion, barely could acknowledge the gesture. In the Australian team’s section of the stands, Titmus’s now-famous and famously exuberant coach, Dean Boxall, went into spasms of joy, arms pumping, veins in his neck popping, long hair flying around his face.

“It is the biggest thing you can pull off in your sporting career,” Titmus said. “So I’m over the moon."

As they circled each other these past few months from their respective homelands, Titmus went to great lengths to paint herself as an underdog — despite going four seconds lower than Ledecky in their respective Olympic trials last month — and Ledecky, in her typical, detached manner, shrugged off any suggestion that Titmus’s times, quotes or mere presence had any bearing on her own mission.

Ledecky hadn’t been under 3:59 since August 2018 and hadn’t been under 3:58 since May of that same year. The last time she raced Titmus, at World Championships in 2019, she lost by more than a full second (though it turned out Ledecky was ill, which forced her to scratch two other races in that meet).

But when Ledecky came out of her prelimary swim Sunday night, a healthy 4:00.45 that led the qualifying field by more than a second, she sounded energized and practically giddy, with a lilt in her voice as she spoke of Team USA’s impressive medal haul on Day 1. She sounded like someone who knew she had a huge swim in her.

Ledecky led Titmus at each of the first five walls, at one point opening a lead of nearly a full body length. Because Ledecky, from Lane 4, breathes almost exclusively to her right, she could see Titmus, in Lane 3, each trip down the pool. But she had no clear view of her on the way back, and Titmus began to close after the 250-meter mark, gaining half a second on that lap alone. By the final turn, she was ahead by 0.22 seconds.

“I looked up at 300 and was like: ‘Oh! ... She’s right there,'” Ledecky said.

Ledecky threw everything she had into the final 50, coming home in a furious 29.12 seconds — just a whisper off the 28.92 she closed with in Rio.

Titmus’s task over those final 50 meters was one that would have sunk a lesser or less confident swimmer: hold off the greatest female freestyler in history when she was putting everything she had into one final lap. But Titmus found one last stock of energy and surged to the wall. Her final split: an unfathomable 28.67.

“She definitely swam a really smart race,” Ledecky said. “... I didn’t feel like I died or really fell off. I had a fast last 50 — she just had a really fast last 50."

Asked to recall the last time she had swum a great race, only to be beaten by someone who swam better, Ledecky paused, started, stumbled — and finally answered, “Maybe some relays ... Yeah, it’s a rarity for me.”

Ledecky was a 15-year-old, out-of-nowhere phenom when she won gold in the 800 meters at London 2012 and a 19-year-old conqueror at the height of her powers — but still the youngest woman on the U.S. Olympic swim team — when she earned four golds and a relay silver in Rio.

On Monday, she found herself the oldest swimmer in the 400 free final, with only one other swimmer within three years of her. The youngest of her seven competitors, 14-year-old Summer McIntosh of Canada, was a little minnow of 5 years old when Ledecky won her gold medal in London.

There is a perception, at least with casual fans who don’t understand swimming, that all Ledecky has ever had to do was show up, hop in the water, swim a few laps and collect a chunk of gold at the end of her race. It is a notion, fueled by her own outsize success and frequent blowout wins, that discounts the many, many meters she tackles every day in practice, the preparation and focus required to perform at an elite level and the normal human emotions and pressure for which no one, not even Ledecky, has immunity.

“I’m proud of how I got to this point. It’s never an easy journey to the podium,” Ledecky said. “I had to overcome a lot of self-doubt ... I think I just came into this race very much at peace with the work I’d put in to get to this point. I felt good going into it, felt confident, felt like I believed in myself. And I think that’s the biggest win of all.”

Titmus was simply the challenger Ledecky always knew would come along — one inspired by Ledecky herself, able to imagine the preposterous because Ledecky had already shown it possible.

“I wouldn’t be here without her,” Titmus said. “She set this amazing standard for middle-distance freestyle for girls, and if I didn’t have someone like that to chase, I definitely wouldn’t be swimming the way I am. I’m really grateful to have her.”

And what now for Ledecky? That’s easy: She will get herself ready to swim again.

Because of the NBC-driven peculiarities of the Olympic swim schedule — prelims in the evening, semifinals and finals the next morning — Ledecky was in for the mother of all race days Monday: her 400 free final in the morning, followed by qualifying heats of the 200 free and 1,500 free that same evening, the last two separated by less than two hours.

That’s 2,100 meters of racing in one day. By comparison, Michael Phelps, one of the only other swimmers in history to have known a similar sort of dominance, never swam more than 600 meters in a day at the Olympics.

In a normal Olympics — one in which television executives did not have the power to upend athletes’ familiar routines and rhythms — Ledecky would have a solid night’s sleep between those sessions. Here, she would be facing a couple of bus rides and maybe a two-hour nap in between.

And guess which relentless, yellow-capped rival will be waiting for Ledecky in the 200 free starting Monday night? And again later this week in the 800? And most likely the anchor leg of the 4x200 freestyle relay?

Ledecky probably already was thinking ahead to the 200 — and her next clash with Titmus — on the podium Monday, the Australian national anthem ringing through the arena, a medal of unfamiliar hue draped around her neck.