What an amazing night it was: Bethesda’s Katie Ledecky broke a 24-year-old national record for her age group held by Janet Evans in Tuesday’s 400-meter freestyle final at the U.S. Olympic team trials in swimming.

What a disappointing night it was: Despite the brilliant, record-setting swim, Ledecky, 15, finished third in the event — one spot short of securing a berth on the 2012 U.S. Olympic team.

She won big and lost big, all in one heart-wrenching evening that precisely no one in her family would have expected even a year ago as she climbed steadily through the swimming ranks at Curl-Burke Swim Club.

“She broke Janet Evans’s legendary record; that’s an unbelievable accomplishment for a someone who just finished her freshman year in high school,” said her coach, Yuri Suguiyama. But “she got third. What can you say to that?”

Either congratulations or I’m really sorry — or both. Allison Schmitt ran away with first place in the race, finishing in 4 minutes 2.84 seconds, as 2008 Olympian Chloe Sutton hit the wall in 4:04.18 and Ledecky in 4:05 flat.

The result was all the harder to swallow since Ledecky had finished second to Schmitt in the morning heats, topping both Sutton and Great Falls’s Kate Ziegler, who finished seventh in the final in 4:09.17. Towson’s Katie Hoff, the 2008 trials champion in the event, did not advance out of the morning semifinals.

Ledecky admitted that a wave of disappointment hit her when she finished, knowing she hadn’t been able to chase down Sutton. But then she heard the surprising bit of news that generated a resounding ovation. The meet announcer proclaimed that her time surpassed Evans’s 1988 national record of 4:05.45 for 15- and 16-year-olds — which Ledecky will have another year to lower further.

“When I touched, obviously, I thought I didn’t make the team,” Ledecky said by cellphone after warming down after the race. “Then when the announcer announced that I broke Janet Evans’s record, [I thought,] ‘That’s a pretty good second option.’ I guess it made me happy again.”

Earlier in the day, Evans herself swam in the event’s preliminary round at age 40 but finished sixth in her 400 freestyle heat, failing to advance to the final with her time of 4:21.49.

“I wish I would have gone faster,” Evans said after her race. “It’s nice to get the jitters out. I think my 800 will be better.”

Ledecky, who began swimming at age 6 for the Palisades Porpoises of the Montgomery County Swim League, could have made precisely the same statement. The game is far from over for the rising sophomore at Stone Ridge.

She will compete in the 200 freestyle Wednesday and the 800 freestyle Saturday, when she will be a favorite to clinch a spot on the Olympic team. Her parents, who watched in the arena seats with more than a dozen relatives, say they expect an even better effort in the 800.

“We’re just thrilled to be here,” said David Ledecky, her father. “Katie worked really, really hard to get to this level.”

Earlier, there was plenty of joy in the pool after the men’s 100 breaststroke final as Brendan Hansen celebrated a successful return to the sport after a two-year hiatus following the 2008 Summer Games. Hansen won the event, touching the wall in 59.68 seconds, and cancer survivor Eric Shanteau finished second in 1:00.15. Shanteau and Hansen reveled after the race, trading high fives, throwing fists into the air and waving at the crowd.

“In 2008, I didn’t have a lot of fun,” said Hansen, who failed to qualify for the Olympics in his top event, the 200 breast. “I’m having a lot of fun right now.”

In other news, Ryan Lochte and Michael Phelps squared off in the semifinals of the 200 freestyle and finished the race in almost a dead heat. A night after topping Phelps in the final of the 400 individual medley, Lochte edged Phelps by two-hundredths of a second, touching the wall in 1:46.25, the best time of the night. Potomac Falls’s Matt McLean led the first semifinal and posted the fourth best time, finishing in 1:47.40.

Lochte said he cruised until the last 50, when he picked up the pace to try to edge Phelps.

“We just want to win,” Lochte said. “We definitely kicked it into gear in the last 50. . . . [Wednesday] night it’s going be a lot faster.”

Phelps admitted he felt sore Tuesday morning but said he accomplished his goal: grabbing lane near the middle of the pool in Wednesday’s 200 free final.

“It’s going to be another tough race tomorrow,” Phelps said. “It’s probably going to be another close one, too.”

Dana Vollmer claimed the first Olympic berth in the 100-meter fly in 56.50, topping Claire Donahue, who came home in 57.57. Eleven-time Olympic medalist Natalie Coughlin finished seventh in 58.66. Missy Franklin, 17, led the semifinals of the 100 backstroke, topping the field with a time of 59.06.