In "Miracles," the Season 3 finale, Ted tells the story of the taxi ride that changed his life. As he stops to tie his shoes, he missed three cabs and gets into the fourth when... well, Ted backtracks before telling us what happened in the cab.
That morning, at about 10am, Ted arrives at his apartment looking for beer. He is stressed out because while at brunch with Stella, she invited him to her sister's wedding - six months away! She assumed that they would still be together then, and Ted freaked out.
Barney tells the gang his rule to never plan ahead for something that is farther away than the amount of time you've been dating - illustrated by the time he ripped up a pair of Bruce Springsteen concert tickets Ted had bought for a date. Ted had been dating this particular girl for just two weeks and Barney told him that he wouldn't even remember "Robin" by the time the concert came around...
When Stella invites Ted to her sister's wedding, Ted clams up and tells her they "need to talk." When they're finished "talking," Stella walks away.
When Lily hears Ted's story, she smacks him for his commitment-phobic ways. But Ted explains that he is worried that if he's feelings now, it probably won't be the last time; he would rather break up with Stella now than six months down the line.
Back to the cab ride: Finished tying his shoes, Ted takes the fourth taxi to pass him - only to get into an accident.
The hospital calls Marshall, who calls Lily, who calls Robin. They all rush to the hospital, running in slow motion to an ominously sad song, and arrive at the hospital to find Ted is unharmed, eating Jell-O.
While he is fine physically, Ted is emotionally distraught and having second thoughts about how he left things with Stella. Being unhurt in the accident is giving him a second chance, and he wants to get back together with Stella.
Marshall insists that the accident was a miracle and gets laughed at by Robin, who says there's no such thing.
Marshall fights back: The scene is MacLaren's Pub, March 2006. Barney, Marshall and Ted are throwing pencils in the air, trying to get them to stick to the bar ceiling. One of the pencils drops back down, bounces off the ground, and lodges itself straight up inside of Barney's nose - but causes no injury.
Marshall rests his case; miracles do exist.
Upon hearing Barney's name, Lily remembers she never called to tell him Ted was in the hospital. She calls him, but Barney hangs up on her. Lily pretends that he's still on the line and starts a make-believe conversation, but but Ted figures it out.
Barney hightails it out of a meeting, someone takes his cab, and he starts running for the hospital.
Back at the hospital, Robin again tells Marshall there is no such thing as miracles. This time, his example takes us to John F. Kennedy airport, July 1999. Marshall is returning from a trip to Amsterdam and looks concerned as he passes his bag to the security guard. In a stroke of luck - a miracle - the guards change shifts at that moment. The new guard looks Marshall up and down, and says, "Amsterdam - Float on through, brother" and gives him the peace sign. He takes one look at Marshall and says "Amsterdam, float on through brother" as he flashes Marshall a peace sign.
Finally, Stella arrives at the hospital. Ted tells her he loves her and asks if they can start fresh. Stella jumps on top of him. Again, Marshall calls it a miracle. Robin, of course, still disagrees.
Lily's kindergarten class - April 2008: Marshall is having a crisis and contemplates begging for his old job at the law firm. Lily steps out to get more glue for her students and asks Marshall to watch the kids while she's out.
to entertain them, Marshall tries on the children's hats and performs moments from history. We then flash forward to Marshall, back at the law firm, in his bosses' office. He apologizes and his boss agrees to give him another chance. Then Marshall's head starts to itch really bad. He caught lice from the kids' hats! He can't think of anything but the itch, freaks out and yells out that he has lice. His boss gets angry, yells back at him and tells him to get out. If he hadn't gotten lice, he would have been back at his old job two weeks later when the authorities showed up. A miracle, he says. Robin is not convinced.
When Stella leaves Ted's room, Lily gives her a hug and says she's happy they're back together. Stella starts to explain that she and Ted never broke up, but realizes that as far as Ted was concerned, they had broken up.
Stella confronts Ted; he tells her to forget what happened, but she can shake the feeling that Ted really had wanted to break up with her. She tells him that if he felt this way now, he'll feel that way again. This time their breakup is mutual.
Next, Ted gets a call from a nurse; he is Barney's emergency contact. Apparently, after running the entire way to the hospital, Barney was exhausted and distracted by the sight of the guy who stole his cab walking into the hospital. Not paying attention to where he was going, he stepped out into the road, right in front of a bus.
Ted's and Barney's reunion is emotional, with the pair proclaiming they aren't just friends, but brothers. Marshall now insists that two miracles occurred today. A frustrated Robin sticks out her tongue at him. Marshall finally asks why she doesn't believe in miracles.
Apparently, when Robin was little her pet dog got sick and had to be put to sleep. But to protect her, Robin's parents came up with an elaborate ruse: her dog's life was saved thanks to a new procedure, they told her, but the side effect was that he had been transformed into a turtle. She was bummed that her dog had forgotten his old tricks in the process, but was happy he was alive. Years passed before she realized what had really happened.
When Ted is released from the hospital, he rushes to find Stella. Marshall asks Barney what flashed before his eyes before he was hit by the bus. Lily and Marshall joke that he probably saw boobs, suits and scotch, but as they laugh Robin walks in and Barney stares at her quietly for a long time.
When Ted tracks Stella down, he tells her the accident changed him. He asks her to marry him.