Maya DiRado edges out Hungary’s Katinka Hosszu to win gold in the 200-meter backstroke. (Jonathan Newton/The Washington Post)

For more than a dozen years, Michael Phelps had defined and all but consumed the sport of swimming. Other athletes accomplished lifelong goals, set world records, won Olympic medals. To a degree, they were all in his wake.

So maybe this was the perfect way to begin the wind-down of an epic career. The headline Friday night could well have blared, “Phelps loses!” Accurate, of course, because in the 100-meter butterfly, he was beaten by Joseph Schooling of Singapore — the first event at the Rio de Janeiro Games, Phelps’s fifth Olympics, in which he didn’t take gold, instead tying for silver.

And afterward, in what for him amounted to a loss, he fairly beamed.

“It’s all I can ask for,” Phelps said, grinning. “It’s fun. It’s a silver medal. Add that to the collection.”

But really, the silver allowed the focus to go to the collection won by other Americans. For one night, Phelps, one of the fiercest competitors in his sport — or in sports in general — could step aside and pump his fist at the edge of the spotlight dominated by others. There was gold for the U.S. team in both completely expected and utterly surprising ways — first from Maya DiRado in the women’s 200-meter backstroke, in which she beat three-time gold medalist Katinka Hosszu of Hungary; next came the sport-altering dominance of Bethesda’s Katie Ledecky in the 800 freestyle, a world record and her fourth gold.

And, finally, with the coffers full, 21.40 seconds that could fill a book. Anthony Ervin first won the 50-meter freestyle at the 2000 Sydney Olympics, back when he was 19, Phelps 15. He then wandered through a personal wilderness in his 20s, re-emerging to make the 2012 Olympic team. Friday night, at age 35, he again won gold in the madness that is the 50 free, covering that length in those 21.40 seconds, beating France’s Florent Manaudou by a single hundredth of a second and compatriot Nathan Adrian by 0.09.

That guy flexing in the pool? That would be the oldest winner of an individual Olympic swimming race.

“This whole day’s been kind of crazy,” DiRado said.

And she swam first.

Start there, then, because her story is compelling. At 23, she is in her first Olympics. At 23, she is in her last Olympics, because she is retiring and taking a day job at a consulting firm in Atlanta. So she decided to make this one count. When she entered the pool Friday, she already had a silver in the 400 individual medley, a bronze in the 200 IM, and gold in the 4x200 freestyle relay. She had been inspired by Simone Manuel, her Stanford teammate, winning gold in the 100 free Thursday night. And she spent the day ticking off a list of lasts — last warmup and the like.

Then she wrote her parents a letter, thanking them.

“I was bawling on my bed,” she said.

In the water, she glowed. Hosszu, a force here, was the clear favorite. DiRado trailed her by nearly six-tenths of a second at the midway point. She trailed her by more than half a second with one length of the pool to go. With 15 meters left, she appeared to trail still.

“I heard the crowd getting louder and louder and louder,” she said, “so I knew we were neck and neck.”

DiRado reached, touched — and processed the result: 2:05.99, 0.06 seconds faster than Hosszu. The tears began.

“We got a lot of young kids,” Phelps said. “And I think we showed what kind of talent we have.”

The kids, of course, would not include Ervin, who provided one more for the old guys — and thanked everyone who had helped him through a circuitous path. “I hope they can always lean on me if they need it,” Ervin said.

That group of kids no longer includes Phelps, either. This was the 18th final of his Olympic career, a string that started when he was 15 in Sydney and finished fifth in his only event, the 200 butterfly. He had won everything he had entered to this point here, at age 31, two individual races and two relays, and his results in the Olympic 100 fly: gold, three times over. He was beginning to feel infallible again.

Yet after one length of the pool, he was in sixth.

“It’s what I had,” he said, and not only was Schooling, who swims at the University of Texas, looking studly, but some of the best adversaries from Phelps’s past were right there — South Africa’s Chad le Clos and Hungary’s Laszlo Cseh. Phelps surged, and had he been a hundredth slower, he would have lost a medal altogether. As it turned out, he touched in 51.14 seconds — tied with both le Clos and Cseh for silver, the 27th Olympic medal of his career.

“It’s kind of a wild ending to the story,” Phelps said.

The ending, though, comes Saturday night, when Phelps will swim the butterfly leg of the medley relay. His individual racing career is over, and his win-loss record at the Olympics is more like that of a Cy Young candidate that a swimmer: 13-5, failing to medal only twice.

“I don’t know if anybody can ever carry the torch that Michael’s carried for us the past 16 years,” Ledecky said.

Now he needs only to carry it for one more night. But the transition began Friday, when three American swimmers stood on the top of the podium, none of them named Phelps. He stood a level down, listened to another anthem — and smiled broadly, somehow fully satisfied.