RIO DE JANEIRO — It was closing night Friday for the Maryland double feature that's done bang-up business at the Olympic Aquatics Center.

First up, Baltimore's Michael Phelps sought his fourth straight gold medal in the 100-meter butterfly, the last individual race of his 16-year Olympic career.

Minutes later, Bethesda's Katie Ledecky mounted her starting block for the 800 freestyle final, her last race of the 2016 Games and one in which she was expected to annihilate her world record.

Ledecky followed through, winning in 8 minutes, 4.79 seconds to capture her fourth gold medal and fifth medal overall of these Olympics. She won by nearly 12 seconds, leaving her top rivals half a pool behind.

Phelps, however, started slowly, hitting the 50-meter turn in sixth place. He rallied but could not catch Joseph Schooling, 21, of Singapore, who won in Olympic-record time of 50.39 seconds. Phelps finished in 51.14 and in a three-way tie for silver with Chad le Clos of South Africa and Laszlo Cseh of Hungary.

“It's what I had,” Phelps said. “It's been a really long week, and I knew this was going to be a tough one.”

It was the first of his five finals this week in which he didn't win a gold medal. But he seemed less distraught than he might have in previous years, grinning his way through a postrace interview and wrapping Maya DiRado in a bearhug after her stirring rally to win gold in the 200 backstroke.

“I'm me, so I'm going to be hard on myself a little bit, because I don't like to lose,” he said. “But I'm accepting it. I'm accepting the race that I had tonight.”

Phelps pushed his career total to 27 medals, 22 of them gold. He and Ledecky, who grew up 45 minutes apart in different Maryland suburbs, have totaled 10 medals at these games, with eight gold. Phelps will have a chance to add one today in the 4x100 medley relay, the swim he says will be the last of his career.

For the first time since Sunday, he had only one race to swim. And he needed the whole day to rest after a grueling Thursday schedule that included his victory in the 200 individual medley and his preliminary and semifinal swims in the 100 butterfly.

His butterfly semifinal started about 30 minutes after his swim in the 200?IM, and he also had to stand through a medal ceremony before the race. The same double had racked his 31-year-old body at the U.S. trials. But he got through this one in good order, qualifying fifth for the butterfly final despite a sluggish first 50 meters.

“I know it seemed counterintuitive, but he didn't have to push that too hard,” coach Bob Bowman said.

Nonetheless, the 100 butterfly set up as one of his most difficult events of the week. It again pitted Phelps against his young rival, le Clos, who was looking for revenge after what he called “the worst performance of my career” in the 200 butterfly final.

And there was Schooling, who swam the top qualifying time and beat Phelps in the 100 butterfly in Austin, Texas, on June 3, and who grew up transfixed by Phelps' races. He said he was honored just to swim a final with the greatest ever.

“I don't know what to believe,” he said. “Whether I actually did it or whether I'm still preparing for my race. I need to chill by myself and realize what I've done.”

Though Phelps' record in the 100 butterfly suggests utter dominance, he had won his previous three gold medals by a combined 0.28 of a second. In 2008, he needed a miraculous lunge to the wall to beat Serbian Milorad Cavic by .01 of a second, Phelps' closest call during his record-setting run to eight gold medals at the Beijing Games.

“There's nothing I can do,” Phelps said after Friday's race. “Last night, I probably got the most sleep I've gotten all week. Like I said, hats off to Joe. I'm looking forward to watching how he progresses over the next four years.”

Ledecky, meanwhile, faced little opposition beyond her own history in the 800. Her world record, set in January, was nearly 12 seconds faster than the time of anyone else in 2016 and almost eight seconds faster than the time of anyone else in history. She set an Olympic record Thursday while hardly kicking for most of the race. She came into Friday with the top dozen times ever.

Ledecky broke down after the race when she spoke with reporters and again when she saw her coach, Bruce Gemmell. It was a rare display from the even-tempered teen. “I think it was because this was the last one of the week and I had so much fun,” she said.

She also paid tribute to Phelps. “He inspired many of us when we were young,” she said. “His impact will continue to live on for many years to come.”

Her quest for a new 800 frontier felt like a valedictory address as much as a race. Ledecky, 19, was projected to be one of the breakout stars of the 2016 Games, and her swims this week have offered an array of pleasures for swimming connoisseurs.

If you like untouchable supremacy, she dished that up in her 400 freestyle swims. If you like watching the best swimmer in the world scrap for victory in her most challenging event, she did that in the 200 freestyle. If you like watching an individual force of nature change the course of a team event, look no further than her anchor leg in the 4x200 relay.

Before Ledecky jumped into the pool for that swim, her teammate Allison Schmitt told her: “Katie, you know everyone in here is scared to swim against you. You got this.”

“She gave a little snicker,” Schmitt said. “And I knew then that she had it.”

Ledecky's admirers include many of the biggest names in the sport.

“She's getting so much faster that she's starting to beat my times in distance events, which is crazy,” 12-time Olympic medalist Ryan Lochte said. “Anytime she gets in that water, she's going to do something amazing. She's so young, and she has so much determination. She just loves the sport. She's going to keep doing it and keep breaking records. There's no doubt in my mind.”

Bowman called her victory in the 400 freestyle final “the best swim that's ever been done.” Needless to say, he's been up close for some pretty great swims.

He sees Ledecky as the obvious candidate to replace the retiring Phelps as the face of American swimming.

“I think she definitely could,” Bowman said. “She's probably the only person. Katie doesn't swim as many events. The distances vary. But, yeah, she's as dominant as it gets.”

In his role as team uncle, Phelps went further, praising the entire next generation of U.S. swimmers.

“We got a lot of young kids, and I think we showed how much talent they have here,” he said. “There's a lot of excitement on the team, and that's something fun for me to watch.”

childs.walker@baltsun.com

twitter.com/ChildsWalker