RIO DE JANEIRO -- Standing atop the medal podium for the 23rd time, Michael Phelps teared up, bit his lip and gave a little nod.
This was how he wanted to go out: on top of his game in the water and totally content away from the pool.
"It turned out pretty cool,'' Phelps said with another gold medal around his neck. "It's just a perfect way to finish."
Phelps put the United States ahead to stay on the butterfly leg of the 4x100-meter medley relay, which gave the most decorated athlete in Olympic history his 23rd career gold medal Saturday night.
If that was the end -- and Phelps insists it is -- the numbers are simply astonishing. No other Olympian has more than nine gold medals. With 28 medals in all, Phelps is 10 clear of anyone else.
"It's not even once in a generation," said his coach, Bob Bowman. "It might be once in 10 generations that someone like Michael Phelps comes along."
As Nathan Adrian touched the wall to finish the victory, Phelps gathered the other relay swimmers, Ryan Murphy and Cody Miller, in his arms. One night after his only setback of the games, an upset loss to Joseph Schooling in the 100 fly, Phelps was back on top.
At age 31, he leaves Rio with five golds and a silver.
"I wouldn't change anything," he said. "This is the best place I've ever been in my life."
In the stands, his fiancée, Nicole Johnson, bounced along to the music with their son, 3-month-old Boomer, cradled in her arms. Phelps is eager to spend a lot more time with them. He plans to marry Johnson after the Olympics and said he wants to watch his son grow -- and maybe even dole out a swimming lesson or two.
What if Boomer wants to take all those medals to show-and-tell someday?
"I might let him take one," Phelps said with a grin.
"Maybe a bronze," Bowman chimed in.
Most of the U.S. swim team was in the stands to watch Phelps' finale, including the biggest female star at the pool, Katie Ledecky. The 19-year-old Ledecky joked that she was proud to be part of Phelps' final Olympics -- twice. He initially retired after the 2012 London Olympics, only to decide about a year later to return.
The comeback endured a huge setback with his second drunken-driving arrest in 2014, which led to Phelps' being banned from the world championships last year. But it also sparked a turnaround in his personal life. He entered six weeks of inpatient therapy, and he got in touch with some of the issues that seemed to lead him astray.
He quit drinking, reconnected with his estranged father, got engaged, moved to Arizona along with Bowman and became a father for the first time. Phelps sounds much more adamant this time when he says his swimming career is over.
"These games really showed his growth," teammate Anthony Ervin said. "That human spirit, that capacity to heal, I think it showed in his swimming, it showed in his demeanor, and it certainly showed in his leadership on the team."
Phelps was elected a team captain for the first time in his fifth Olympics and truly seemed to enjoy being around his fellow swimmers. He was still the same ruthless competitor, but he was also willing to join in when some of his younger teammates made a carpool karaoke video at their final training camp in Atlanta. He took a starring role, in fact.
"Being Michael requires such isolation," Ervin said. "Other people respect that. They give him that space because he is the greatest. But this time around, he started reaching out, reaching out to other people, bringing them closer, letting that gap be bridged. That was special."
On a victory stroll around the pool, Phelps and his teammates grabbed a sign that said, "Thank You, Rio."
"No matter what country you swim for, you're indebted to Michael Phelps for bringing a lot of exposure to the sport and making it a little more mainstream," Murphy said. "If this is the end, that was a great way to cap off an incredible career."
"It's not even once in a generation. It might be once in 10 generations that someone like Michael Phelps comes along." Michael Phelps' coach, Bob Bowman
Murphy, who won two backstroke golds in Rio, put the Americans out front with a world-record split -- it counts because he was leading off -- before Britain surged ahead on the breaststroke with its own world-record holder, Adam Peaty.
Phelps dived into the pool in second place. He wasn't there for long. On the return lap, Phelps powered through the water with his windmill of a stroke and surged ahead of James Guy to pass a lead to anchor Adrian.
The race wasn't in doubt after that. Adrian pulled away on the freestyle to win in an Olympic-record time of 3 minutes, 27.95 seconds. Britain held on for silver (3:29.24), with Australia nabbing bronze (3:29.93).
"I think you could tell: I was more emotional after the relay this time than I was the last time," Phelps told NBC after the race. "It's been an honor to be a part of all these relays. ... I've had the opportunity to be on some of the greatest relays of all time. It's been an honor."
Phelps leaves the pool with a record 23 Olympic gold medals in 30 Olympic finals.
"Watching his first gold medal in Athens, [Phelps] is someone I've looked up to my whole life," Murphy said. "To swim that last race with him and get gold, it's really a dream come true."
Phelps has maintained that Rio will be his final Olympic Games. After Saturday's race, he told NBC, "I'm just ready for something different. My swimming career might be over, but I have this future ahead of me, and I can just turn the page and start whatever I want.
"It's not the end of a career. It's the beginning of a new journey. I'm really looking forward to that."
Saturday's victory came just minutes after the women's medley relay gave the United States its 1,000th Olympic gold medal at the Summer Games. The U.S. has won 33 swimming medals at Rio 2016, its most since 33 at the Sydney Games in 2000.
The final two individual golds of the games went to Pernille Blume of Denmark in the 50m freestyle, her country's first swimming victory since 1948, and Italy's Gregorio Paltrinieri in the grueling 1,500m free. Connor Jaeger of the United States took silver in 14:39.48, while the bronze went to another Italian, Gabriele Detti, in 14:40.86.
But the night belonged to Phelps, who walked out of the arena for the final time carrying the American flag that his mother handed him from her front-row seat, right next to Johnson and little Boomer, with a gold medal around his neck.
Information from The Associated Press was used in this report.