Correction: An earlier version of this article incorrectly ­described Katie Ledecky as a rising junior at Stone Ridge School of the ­Sacred Heart in Bethesda. She is between her freshman and sophomore years at Stone Ridge. This version has been corrected.

Four years ago, it never crossed the mind of Bethesda’s Katie Ledecky that she could win a spot on the 2012 U.S. Olympic team. Back then, Great Falls’s Kate Ziegler did not even consider that she would want that opportunity.

Yet on Sunday night, Ledecky, 15, and Ziegler, 24, wore joyous, disbelieving grins as they absorbed the result of the 800-meter freestyle final at the U.S. Olympic team trials in swimming.

Ledecky, a rising sophomore at Stone Ridge and newcomer to the international swimming scene, seized her dream far earlier than she expected, putting down a resounding victory in the 800 free in an Olympic trials record time of 8 minutes 19.78 seconds as Ziegler snagged second place — and the other Olympic berth — in 8:21.87.

“It’s unreal,” Ledecky said. “It’s unbelievable.”

Ledecky became the youngest member of this year’s Olympic swim team while Ziegler, who dabbled in retirement after the 2008 Summer Games in Beijing, earned an opportunity to have a better experience than she did four years ago, when burnout and the immense pressure left her wishing she were anywhere else.

“The last four years has been a little bit of a roller-coaster ride, but it’s been a really good journey,” Ziegler said. “My disappointments have definitely shaped me into the swimmer I am today. . . . I couldn’t be more thankful to have the opportunity to go to the Olympics.”

The Potomac Valley dominance in the 800 capped an eventful night here. Missy Franklin, 17, won the 200 backstroke in 2:06.12, clinching a spot in her fourth individual event and giving her the hope of contending for seven medals in London.

“I’m so happy,” Franklin said. “I can’t believe I have seven events. It’s so overwhelming but so exciting at the same time.”

Michael Phelps defeated Ryan Lochte for the third time in four races, dominating the 100 butterfly with a victory in 51.14 as Tyler McGill claimed second in 51.32.

Lochte, competing in an event he rarely swims, produced an impressive time — 51.65 seconds — but couldn’t squeeze into the top two in the event. That meant no Olympic berth and no hope of swimming in the 4x100 medley relay final in London. While Phelps once again chases eight gold medals, Lochte will have the chance to contend for just six.

“I have no regrets,” Lochte said. The 100 fly “was fun. It was something I’d never done before at a big swim meet.”

In other news, Cullen Jones claimed the men’s 50 freestyle title in 21.59 seconds as Anthony Ervin, 31, completed an unlikely journey from a seven-year retirement to the Olympic Games. The 2000 Olympic gold medal winner finished in second place in 21.60. In the night’s last event, Dara Torres, 45, earned a spot in Monday’s final of the 50 freestyle by posting the third-fastest time (24.80) in the semifinals.

“I’m ecstatic,” Torres said. “It wasn’t all I’ve got.”

After touching the wall in the 800, Ledecky spun to look at the giant scoreboard hanging over the pool and pumped her fist emphatically. Ziegler threw her head back into the water, savoring the moment. Ledecky’s brother Michael, who will be a freshman at Harvard in the fall and has contributed to The Post’s coverage here, stood near the media area shouting, pumping his fists, jumping up and down and clutching his head in disbelief.

“I was just real emotional,” said Yuri Suguiyama, her coach at the Curl-Burke Swim Club. “You’re talking about a 15-year-old lady who comes to the pool every day with a smile on her face and an unbelievable work ethic. I was just really proud, really happy for her. She earned it.”

Ledecky, whose mother Mary Gen Ledecky swam at the University of New Mexico, and Ziegler exchanged an embrace and excited words before exiting the water. Ziegler said she would love the opportunity to act as a mentor for the youngster across the Potomac River, to help her have a smoother first Games than Ziegler herself did. A two-time world champion in the 800 and 1,500 freestyle entering the Games, Ziegler finished 14th and 10th, respectively, in the 400 and 800 free.

“I’m excited for her,” Ziegler said. “I started out on my first international team when I was 16 years old or so, and I looked up to the older swimmers. . . . I would love to be able to leave the sport saying that I helped mentor or shape or whatever, give advice to the future of our sport. I think that’s one of the greatest gifts I could ever give.”

Ziegler, who held off Haley Anderson (8:26.60) and Chloe Sutton (8:28.12), took time off to decompress after Beijing, then moved to Fullerton, Calif., to try to jump-start her career. Late this winter, she faced upheaval again as she returned to work under her longtime coach at the Fish, Ray Benecki.

Ledecky, who barely missed making the team in the 400 freestyle here with a third-place finish, owned Sunday’s race from start to finish. She said she went out faster than she intended and faster than instructed. But it paid off; she broke the 2008 trials record (8:20.81) held by Towson’s Katie Hoff, who did not make the Olympic team at this meet.

“I don’t think I was supposed to go out that fast,” Ledecky said. “I wasn’t really planning to go out that fast. . . . I never told myself I had it. I just kept trying to hold the same pace.”

Said Ziegler: “The experience she has ahead of her is so exciting.”