As Michael Phelps finished the last lap of his last training session before his last night of Olympic swimming, Bob Bowman, his longtime coach, started feeling the emotion swell. He later said he felt uncomfortable and weird.

And then Phelps, his historic career hours from concluding, poked his head out of the water and summoned his coach of 16 years to the side of the pool.

“I’ve been able to become the best swimmer of all time,” Phelps told Bowman, he recalled later. “I said, ‘We got here together.’ I thanked him.”

That’s when Bowman lost it, spilling tears that would leave his eyes reddened throughout the last night of the Olympic swimming competition, which would feature Phelps’s final act: a gold medal as part of the U.S. 4x100 medley relay team.

“My tears I can hide behind my goggles,” Phelps said to his weeping coach. “Yours are streaming down your face.”

It was a night of tears, reflection and joy as one era ended and another bloomed. Phelps’s final victory came immediately after the U.S. women’s squad, featuring 17-year-old Missy Franklin, went under the world record in the 4x100 medley relay, winning the gold in 3 minutes 52.05 seconds. With Phelps swimming the butterfly leg, the men touched home in 3:29.35.

As Phelps wrapped up his career with 22 Olympic medals, the meet unveiled his apparent female heir. “It is unreal,” Franklin said, adding later, “I don’t think his footsteps will ever be filled.”

Both she and Phelps, who has spent his entire career at the North Baltimore Aquatic Club, collected four gold medals here, winning two individual events and two relays; she added a bronze in the 4x200 individual medley relay, he got a silver in the 4x100 freestyle relay and 200 butterfly.

It was hard to tell who had more fun. Franklin, who won the 100 and 200 backstroke events while setting a world record in the 200, seized the stage with nightly displays of fearlessness and joy; she surely set the world record for enthusiastic adjectives and adverbs during news conferences. Every performance, it seemed, was unbelievably fun. She had absolutely wonderful teammates and, night after night, turned out to be the happiest girl in the world.

“Being here in this type of experience with the most incredible teammates you could ask for around me, it’s absolutely impossible to get grumpy,” she said Friday.

Phelps sounded like the happiest guy, only much more mellow and with fewer superlatives. After starting the meet with a fourth place in the 400 individual medley, he got on a medal roll.

“The first race took the pressure off,” Bowman said. “We were saying, ‘We might as well enjoy it. It doesn’t look like it’s going to go too well; we might as well have fun here.’ ”

Phelps had fun, and then it went well, too. Phelps helped the U.S. men crush the field in the 4x200 freestyle relay. After getting out-touched at the wall in the 200 butterfly, he beat Ryan Lochte, the 400 medley champion, in the 200 individual medley.

“He’s smiling back there,” Dana Vollmer, the 100 fly champion who swam the butterfly leg on the women’s relay, said before the men came out for their news conference. “He’s really here to enjoy the Games . . . He’s absolutely loving it.”

Phelps, 27, got handshakes from many of his opponents and hugs from his teammates. He said he will not be back for the 2016 Games in Rio de Janeiro because he doesn’t want to be competing at age 31. He swam in his first Olympics at age 15 in 2000, finishing fifth in the 200 fly. He won six gold medals and two bronzes in Athens in 2004. He won eight gold medals at the 2008 Summer Games in Beijing.

“I’ve been able to do everything I wanted,” he said. “I’ve been able to put my mind to goals I wanted to achieve, and Bob and I somehow have managed to do every single thing. When can you say that about your career? . . . It’s time to do other things.”

Phelps’s impact on the sport has been dramatic. USA Swimming saw an unprecedented membership surge of 11.3 percent in 2009. The number of boys in the sport has grown from 90,000 in 2004 to about 122,000 in 2010 — an increase of more than 30 percent.

“What Michael did for the sport, we’ll appreciate forever,” said Matt Grevers, who swam the backstroke leg on the relay.

U.S. swimmers said Phelps’s influence on his teammates here was equally emphatic. At one of the team’s earliest meetings, Phelps announced that he wouldn’t remember his 14 gold medals — the number he had before the meet began — as much as the card games, the jokes, the conversations and fun.

“He’s never really stood up and said anything before,” said three-time Olympian Brendan Hansen, who won a bronze in the 100 breaststroke and was part of the winning medley relay. “It was really good for our rookies to hear that.”

Added Hansen: “It was really good for me to hear that.”

When Phelps broke onto the international scene at the 2003 world championships, he was a skinny, hard-working, performance-obsessed swimmer who usually deferred to Bowman for comment. He had little to say, and even less perspective, Bowman recalled.

“He was learning a lot, but he was only focused on that. . . . Now, I think he really appreciates what sports mean,” Bowman said.

Phelps didn’t have the most impressive night Saturday — that distinction belonged to China’s Sun Yang, who obliterated his world record in winning the 1,500 freestyle in 14:31.02 – but he got the biggest party.

At the end of the night, the end of his career, Phelps received an unexpected surprise: a silver trophy from the world swimming governing body (FINA). The crowd showered him with appreciation, and Bowman did a bit more crying.

“We’ve had a great end to a great run,” Bowman said. “There’s not much more we can do.”