There’s a reason why there aren’t many comedy Westerns, and even fewer that are actually any good, and that’s because the subgenre as a whole is very difficult to pull off. So you have to credit Seth MacFarlane for not only having the cojones to follow up “Ted” with such an offbeat genre hybrid film, but actually succeed where so many others have failed. “A Million Ways to Die in the West” is probably his most ambitious project to date, and although that may sound strange for a man who made a movie about a talking teddy bear, it’s nice to see a filmmaker with that kind of confidence. Like most things in MacFarlane’s career, “A Million Ways to Die in the West” is guaranteed to divide audiences, but it’s a really solid comedy with more than enough laughs to offset its minor shortcomings.

MacFarlane stars as Albert, a cowardly sheep farmer who’s astutely aware of just how horrible life is in 1882 Arizona. After weaseling his way out of a gun fight, Albert’s embarrassed girlfriend Louise (Amanda Seyfried) dumps him for Foy (Neil Patrick Harris), the arrogant owner of the local moustachery. While contemplating leaving town for a fresh start, Albert saves a beautiful woman named Anna (Charlize Theron) and they immediately bond over their shared hatred of the Wild West. When Albert challenges Foy to a duel in the hope of winning back Louise, Anna agrees to help him become a better gunfighter, falling for the lovable loser in the process. But what Albert doesn’t realize is that Anna is married to a dangerous outlaw named Clinch Leatherwood (Liam Neeson), who rides into town upon hearing of Anna’s infidelity to kill the man that stole his woman.

“A Million Ways to Die in the West” is a very different kind of movie than MacFarlane’s directorial debut, and that’s what makes it so refreshing, because while he could have done pretty much whatever he wanted, he chose to take a risk instead and challenge himself creatively. By setting the film in the 19th century, MacFarlane has effectively forced himself to eschew from his usual pop culture references (save for a couple in-jokes that work in the context of the time period) in favor of more observational humor about the general horribleness and idiosyncrasies of the American frontier. Not every joke works, and the toilet humor is completely unnecessary, but there’s a lot of great material here that’s even funnier than some of the best stuff in “Ted,” including a pair of cameos that trump the Sam Jones/“Flash Gordon” sequence.

MacFarlane has gotten a lot of flak for his decision to play the lead role in addition to his directing and co-writing duties, but he’s an incredibly likeable and natural performer with excellent comic timing. His lack of experience may show in the dramatic moments, but that’s why Charlize Theron was such a brilliant piece of casting, because she carries him through those scenes with the effortlessness that you’d expect from an actress of her caliber. And better yet, she seems to be genuinely enjoying herself in a rare comedic performance. Neil Patrick Harris is also amusing in his limited screen time as Albert’s pompous rival, but unfortunately, the same can’t be said of Liam Neeson and Amanda Seyfried, who are saddled with underwritten and humorless roles. Neeson doesn’t even seem like he’s trying, with the decision to use his native Irish accent coming off more like an act of laziness than the unexplained joke it was presumably intended to be.

The biggest problem with the film is that it’s basically a tale of two halves. The first hour is extremely funny, with an almost relentless stream of clever jokes that rarely miss their mark, but it starts to drag in the latter half as it meanders towards its conclusion. MacFarlane simply can’t maintain the fast-paced, laugh-a-minute level of comedy for the length of its nearly two-hour runtime, which begs the question of why the movie even needed to be that long in the first place. “A Million Ways to Die in the West” would have benefited greatly from some stronger supporting characters and a leaner runtime, but that shouldn’t take away from what MacFarlane has accomplished, because it’s one of the funniest comedies of its kind. Mel Brooks would be proud, diarrhea gags and all.