Katie Ledecky (right) and Australia’s Emma McKeon share the silver medal in the women’s 200-meter freestyle. (Adam Pretty/Getty Images)

Olympic champion Katie Ledecky lost for the first time in swimming’s world championships, stunned Wednesday by Italy’s Federica Pellegrini in the 200-meter freestyle in Budapest.

Ledecky, the 20-year-old Stanford swimmer who won four gold medals in the Rio Olympics, was hoping to match fellow U.S. teammate Missy Franklin’s haul of six gold medals, a record for most world titles by a female swimmer, in the competition. On Tuesday, her 1,500-meter freestyle victory had marked 12th gold medal at the world championships, breaking a tie with Franklin for most in women’s swimming history.

“I just didn’t feel really like myself in the middle of that race,” Ledecky said on NBCSN. “It felt like I was scrambling a little bit at the end. That hurts a little bit, but I’m going to come back stronger and be really good in that event the next couple of years.”

Ledecky, who was undefeated in 12 races in three appearances at worlds, finished in a tie with Australia’s Emma McKeon in 1 minute 55.18 seconds, just behind the 1:54.73 by Pellegrini, who holds the world record in the event. Two years ago in Kazan, Russia, Ledecky edged Pellegrini in the event.

Ledecky had won three golds in Budapest and is in the 4×200-meter freestyle relay in which the United States is favored Thursday, and the 800-meter freestyle on Friday and Saturday. She holds the 13 fastest times in that event.

Her 12 gold medals at the world championships trail only Michael Phelps and Ryan Lochte.

More:

Ledecky’s world championships haul is a world record

How Katie Ledecky became better at swimming than anyone is at anything

Katie Ledecky is No. 2? She won a Pac-12 runner-up award.

Shark weak: Michael Phelps loses race to computer-animated shark.