RIO DE JANEIRO — Katie Ledecky of the United States destroyed the field in the 800-meter freestyle on Friday, breaking her own world record to complete a rare Olympic swimming triple.

Ledecky led from the start and inexorably stretched out the gap over her opponents to finish in eight minutes, 4.79 seconds, beating her previous mark of 8:06.68 set in Austin, Texas in January.

Britain’s Jazz Carlin won her second silver medal in 8:16.17, and Boglarka Kapas of Hungary took the bronze.

Ledecky, defending Olympic champion at the distance, added to her golds earlier in the week in the 200 and 400 freestyle and the 4×200 freestyle relay, plus a silver in the 4×100 relay.

The only previous woman to win the 200, 400 and 800 freestyle at the same Games was American Debbie Meyer in 1968.

“I’ve hit all my goals this past week… I just wanted to lay it all out there,” Ledecky said after her final race in Rio.

“This was my last swim and the Olympics are the pinnacle of our sport.

“I have to wait another four years to have this moment and I just wanted to enjoy it all and put my very best swim out there.”

Ledecky sliced 1.89 seconds off her own record in the longest event of the women’s swimming program.

It was the seventh world swimming record of the Rio Games, and the second by Ledecky, who achieved a similar feat in winning the 400 freestyle.

Since winning the 800 in London four years ago, she has been invincible, and anything but a victory for the 19-year-old would have been one of the biggest shocks of the Games.

Carlin and Kapas fought a dogged struggle for second, with Spain’s Mireia Belmonte Garcia challenging them for much of the way.

Earlier, Joseph Schooling won the men’s 100-meter butterfly final to secure Singapore’s first Olympic gold medal and deny Michael Phelps a 23rd in the last individual race of the American’s extraordinary career.

Phelps, the defending champion and world record holder who is heading into retirement — again — after Rio, finished second in a three-way dead heat with two of his greatest rivals — South Africa’s Chad Le Clos and Hungary’s Laszlo Cseh.

Astonishingly, all three touched out in 51.14 seconds, behind Schooling’s Olympic record 50.39.

Phelps, who now has 27 medals, had been hoping to win the event for the fourth successive Games.

In the women’s 200-meter backstroke, Maya DiRado of the United States won the event, reeling in Hungary’s Katinka Hosszu in the closing meters to deny her a fourth gold medal of the Rio Olympics.

Canada’s Hilary Caldwell won bronze.

Hosszu had led from the start, reacting fastest from the block, but DiRado shadowed her the whole way.

The Hungarian led the American by 0.57 seconds at 100 meters and by 0.48 at the final turn, but DiRado fought back and the two were neck-and-neck as they entered the final 25 meters.

DiRado touched the wall in 2 minutes 5.99 seconds to win by 0.06 seconds.

Turning to look at the scoreboard, her eyes widened and she clapped her hand to her mouth as if she could not believe the result.

“It’s indescribable. That is just pure joy and surprise and excitement,” she said.

Hosszu had already won the 100 backstroke and the 200 and 400 individual medleys in Rio, breaking the world record in the latter.

DiRado, 23, added to her gold in the 4×200 freestyle relay, silver in the 400 individual medley and bronze in the 200 IM.

In the men’s 50 freestyle, Anthony Ervin of the United States reclaimed the mantle of fastest man in the water by taking the gold medal 16 years after he first won it, and by the slimmest of margins.

“I kind of laughed. It’s almost absurd I was able to do it again,” said Ervin of his immediate reaction to seeing his name with the number one against it.

France’s Florent Manaudou, the defending champion, finished second and just 0.01 seconds behind the 35-year-old veteran, who won in 21.40 seconds in a splash and dash down the pool.

Nathan Adrian of the United States took the bronze in the shortest and fastest race on the program. He also finished third in the 100 freestyle on Wednesday.

The entire field was separated by just 0.68 seconds, with Ben Proud of Britain finishing fourth.

Ervin, at 35 the oldest swimmer to win a men’s individual gold, won his first title in a dead-heat in the same event with team mate Gary Hall Jr at the 2000 Sydney Games. Both touched out in 21.98 seconds.

He later sold that medal to raise money for relief efforts after the 2004 Indian Ocean tsunami.

Asked earlier in the week what he would do if he won another, Ervin had replied: “I don’t know. I’m living in the moment, man.”

Heavily tattooed, and as the oldest man on the U.S. swim team making 31-year-old Michael Phelps look comparatively young, the Californian gave up competitive swimming in 2003 but returned for the 2012 Games in London.

Friday’s medal was his second gold from Rio, the first coming in Monday’s 4×100 freestyle. He also has a 4×200 freestyle silver from 2000.

“If anything, I was a little bit slower than I thought I was going to be,” he said.

Meanwhile, earlier Friday, Missy Franklin pledged to return “stronger than ever before” a day after her Olympics came to an abrupt and disappointing end.

In a message to more than 200,000 followers on Facebook, Franklin seemed baffled by the long-running struggles that kept her from advancing to the finals of the 200-meter freestyle or 200-meter backstroke at the Olympic Aquatics Stadium.

“I understand so very little about this past week, about how many sacrifices and endless hours of hard work would leave me so far behind where I thought I was capable of being,” the 21-year-old wrote. “But understanding will not bring me peace. People knowing that I did everything I possibly could have done, that something beautiful will come out of this and that I will come back stronger than ever before.”

A breakout star at the London Olympics with four gold medals and an ever-present smile, Franklin’s good humor remained at these Games, but her performance in the pool wasn’t the same.

She won a gold medal for swimming in the preliminary heat for the 800-meter freestyle relay, but was dropped from the team for the final and faded in the semifinals of both her individual events.

In the 200 backstroke, Franklin’s signature event, her semifinal time was about six seconds slower than the world record she set in 2012.

The reasons for the slower swims — she hasn’t recorded a best time since 2014 — aren’t clear. Franklin insisted she’s healthy and in the best shape of her career. After her final race Thursday, she called the last week the most difficult of her life and expressed relief it was over.

“I felt a little bit like David facing Goliath, but I felt like I didn’t have any stones in my pocket,” Franklin told reporters.

SWIM NOTEBOOK: Therese Alshammar told herself at the 1996 Atlanta Olympics, when she made her debut in the pool as a teenager, that it would probably be a one-off. The Swede, who will be 40 next year, was back on Friday — competing in her sixth Games and racing swimmers half her age to reach the 50 meter freestyle semi-finals in an impressive 24.73 seconds. Simone Manuel, the 20-year-old who won a shared 100 freestyle gold for the United States on Thursday, was only a fraction faster in 24.71. Alshammar smiled when asked whether she accepted the adage that you are only as old as you feel, and if so what her competitive age might be. “How old do I feel? It varies from day to day, I have to say,” she replied. “Some days I feel like I am way past my age and some days I feel younger.” The 38-year-old — she turns 39 on Aug. 26 — became the oldest female swimmer to win a world championship in 2011 with gold in the 50 free and placed sixth at the 2012 London Olympics. A double freestyle silver medallist at the 2000 Sydney Games, her presence in Rio made her the first female swimmer to compete at six Olympics.