The CBS show will be back for a ninth season, according to Deadline.
A deal was reached on Friday after series star Jason Segel agreed to return, the website reported.
The show had been previously considered dead in the water as Segel, whose film career has blossomed greatly since "HIMYM's" 2005 premiere, had "decided to bail and leave the cast hanging," Deadline reported.
However, the "Muppets" star "turned around today at the last second," according to the website.
Alyson Hannigan, who plays Segel's on-screen wife on the sitcom, Tweeted about the cast's return, posting a link to the story with a comment reading, "I'm happy the world(s) didn't end."
In mid-September, "HIMYM" star Neil Patrick Harris told Access Hollywood he didn't anticipate the show lasting past the eighth season (which premiered on September 24).
"Our contracts end at [Season] 8, so it's one of those, you know, if they wanna do 9, they're welcome to, but we have a lot of other things [going on]," Neil Patrick told AccessHollywood.com's Laura Saltman at the time. "Cobie [Smulders] has got 'The Avengers' that just made a billion dollars, Jason [Segel] makes a ton of movies, I'm anxious to move East and Josh [Radnor] is directing and acting in movies as well. So, we all are anxious to move forward."
The actor said the decision would ultimately depend on salary.
"I think the only way I think a Season 9 or any longer would happen would be [if it were] financially right -- that's the reality of it," he said. "We love the show, we love doing it - eight years is a long time and we're as happy a family as we've ever been."
Copyright 2012 by NBC Universal, Inc. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.