The U.S. swimming team won 33 medals in Rio, including in the women’s 4x100-meter medley relay, above. (Jonathan Newton/The Washington Post)

The final event of the 2016 Rio de Janeiro Olympics indoor swim meet, the men’s 4x100-meter medley relay, included a backstroke world record for Team USA and a gold medal, and completed a remarkable eight-day medal haul that re-established U.S. dominance in the pool for another generation.

But this night always will be remembered for the third leg of that medley relay, because it was the final Olympics swim of Michael Phelps’s career. His gold medal, as the butterfly leg in the relay, was the 23rd gold of his career and his 28th overall in Olympic competition, both records that are unlikely to be approached anytime soon.

Ryan Murphy led off the relay with a backstroke leg of 51.85 seconds — a world record for 100 meters — giving breaststroke teammate Cody Miller enough of a cushion to stay close to Britain’s Adam Peaty, the breaststroke world-record holder. That brought the race to Phelps, trailing Britain by a little more than half a second.

Phelps, 31, the silver medalist in the 100 butterfly the night before, retook the lead in his fly leg Saturday night, and freestyler Nathan Adrian brought home the victory. The Americans’ time of 3:27.95 established a new Olympic record.

When the race was over and the gold medal secured, Phelps pulled his teammates close in a huddle.

“That’s when everything started to hit me, knowing that was the last time I’ll wear the stars and stripes in a race,” Phelps said. “I kind of said to the guys what an honor and a privilege it was to be in that relay. It’s been a dream-come-true week.”

With victories in both medley relays Saturday night, the Americans completed the meet with 33 overall medals, including 16 golds, a dominating performance that exceeded the 2012 London total of 31 medals (also 16 golds).

Simone Manuel, one of Team USA’s breakout stars of this meet, won two more medals Saturday night — a gold as the freestyle leg of the women’s medley relay and a silver in the 50 free — to go along with the historic gold she won in the 100 free, which made her the first African American female swimmer to win an individual Olympic medal. She nearly made it a two-gold night, and a three-gold meet, but her time of 24.09 seconds in the 50 free was two-hundredths of a second behind gold medalist Pernille Blume of Denmark.

“I didn’t have too much pressure on me. I didn’t envision anything,” Manuel said. “I just wanted to execute my races as best I could and enjoy the process. Just being on the podium is an amazing honor.”

In the relay, backstroker Kathleen Baker, breaststroker Lilly King and butterfly veteran Dana Vollmer delivered a lead of nearly two seconds to Manuel, who brought home the gold with a solid freestyle leg.

Manuel, 20, entered the meet ranked just eighth in the world in the 50, and fourth in the 100, but medaled in both — while Australia’s Cate Campbell, the world No. 1 in both events this year, was shut out of the medal stand in both, a failure that highlighted the Aussies’ struggles here this week.

Moments after Manuel’s win in the shortest women’s race of the meet, American Connor Jaeger took silver in the longest men’s race of the pool meet, the 1,500 free, with an American-record time of 14:39.48, a little less than five seconds behind gold medalist Gregorio Paltrinieri (14:34.57) of Italy.

Australia was a distant second place in the overall standings, with 10 medals, while Australia and Hungary tied for second in gold medals, with three apiece.