Martha Karolyi, the force behind generations of Olympic champions, concedes that athletes aren’t machines. Still, she tells her gymnasts on the eve of major competitions to “program in” perfection, and they’ll deliver it.

Sunday served as a reminder that it’s not that simple.

Regardless of years of training and endless repetition, something that’s impossible to pinpoint or predict — anxiety in some cases, iron will in others — invariably rises up to spoil one performance and elevate another.

And on a day when near-perfection was demanded, reigning world all-around champion Jordyn Wieber was merely better than most. As a result, she missed the cut for the London Olympics all-around final, finishing third behind teammates Aly Raisman and Gabby Douglas.

“She has trained her entire life for this day, and to have it turn out anything less than she deserves is going to be devastating,” Wieber’s coach, John Geddert, said in a statement issued by the team.

Wieber offered only tears, walking past reporters with her head bowed, still weeping long after the scoreboard showed that Raisman’s bold and well-executed floor routine, the final event in Sunday’s qualifications at North Greenwich Arena, had vaulted her ahead of Wieber and Douglas in the final standings.

Because countries can enter just two gymnasts in the all-around final, the fact that Wieber finished third among U.S. gymnasts (0.233 of a point behind Douglas) and fourth overall offered no solace.

As a team, the United States ruled the day, finishing with 181.863 points to Russia’s 180.429. Defending Olympic champion China was third (176.637).

Neither Karolyi, national coordinator of the U.S. women’s gymnastics team, nor her husband, Bela, could recall an occasion in more than four decades of coaching in which the reigning world champion failed to qualify for the all-around final in the Olympics.

Sunday’s outcome was all the more shocking because Wieber, 17, from DeWitt, Mich., has been the most versatile and consistent gymnast on the U.S. team. Martha Karolyi compared her mental toughness with that of three-time gold medalist Nadia Comaneci of Romania, the first woman to score a perfect 10 in the Olympics. And Wieber arrived in London favored to follow in the gilded footsteps of Americans Mary Lou Retton, Carly Patterson and Nastia Liukin, who won the coveted all-around gold in 1984, 2004 and 2008 respectively.

“It hurts my heart,” said Bela Karolyi, who has no formal role with the U.S. team but remains steeped in the sport. “”I’m hurting inside — for just the principle and for a kid that really puts heart and soul into this and should deserve, on previous performance, to be an all-arounder.”

No one suggested that Raisman and Douglas hadn’t deserved the marks they got Sunday.

Martha Karolyi beamed over Raisman’s performance and told her so by cradling her face in her hands, as she did all five gymnasts who competed for the United States.

“Aly Raisman’s success is proof that hard work pays off,” Martha Karolyi said. “She is the hardest-working, most dedicated person. Finally, she gets the payoff for her hard work.”

Said Steve Penny, president of USA Gymnastics: “Jordyn didn’t have as good a day as Aly did. And Gabby had a great day, too. So the results are what they’re supposed to be. And that’s the way the game is played.”

Still, Raisman, 18, who is the team’s captain and Wieber’s roommate, as well as her best friend, conceded that she felt a difficult sort of joy, advancing to Thursday’s all-around final while Wieber would not.

“It’s really hard, of course, just because we’re best friends, and I know how bad she wanted it,” said Raisman, of Needham, Mass. “That was one of the first things I said, that I feel so bad because she worked so hard, too. It’s tough that only the top two gymnasts go [to the final]. But I know she is still a good friend and she’ll still be happy for me.”

While there was nothing controversial about the outcome — no allegations of favoritism, no disputes over scores — Bela Karolyi afterward faulted the order in which the U.S. gymnasts performed on each apparatus.

It’s customary for countries to send out their weakest gymnast first and close with their strongest performer. Wieber wasn’t chosen to go last (or “anchor” her team) on any of the events, while Raisman was chosen to go last on the beam and floor.

In Karolyi’s view, that indicated to the judges that Raisman was the better gymnast and deserved the higher score.

“This is a definite lineup mistake,” Bela Karolyi said. “Wieber should have anchored on the floor.”

The U.S. lineup was decided by a vote of the five gymnasts’ individual coaches. According to Bela Karolyi, Martha Karolyi had recommended that Wieber go last on the floor exercise, but the U.S. coaches rejected her proposal.

That said, it’s difficult to believe that a different starting order would have altered the outcome.

Wieber didn’t score the highest mark for the U.S. team on any apparatus, finishing second on the vault, third on the uneven bars, fourth on the balance beam and second on floor.

Four gymnasts qualified for at least one event final: Raisman (beam, floor), Douglas (uneven bars, beam), Wieber (floor) and McKayla Maroney (vault).

The pressing question now is whether Wieber can regroup and perform better in Tuesday’s team final, in which three gymnasts perform on each apparatus, and all three scores count.

“We will have to support her, and we will have to explain that this is sport,” Martha Karolyi said. “Things happen. You have to be able to turn the page.”