How I Met Your Mother has been called one of the best sitcoms of the 21st century, due to its engaging premise, hilarious writing and lovable ensemble cast. Barney Stinson, with his charming and sometimes insane womanizer ways, has been of the funniest of the main characters.

RELATED: How I Met Your Mother: 10 Girlfriends Of Ted & Barney That We’d All Love To Date

While he did become a better guy throughout the show, he was, for the most part, a selfish, irresponsible jerk...or was he? Here are 5 times Barney was the best person in the gang, and 5 times he wasn't.

Worst - Slept With His Best Friend's Ex

One of the things fans (and the gang) dislike most dislike about Barney is the fact that despite knowing Ted would be uncomfortable and even angry about it, Barney still hooks up with Robin in "Sandcastles in the Sand".

RELATED: How I Met Your Mother: 10 Reasons Ted And Robin Aren't Real Friends

Even worse is the fact that not only does he try to hide it, but he also breaks a rule he made - "No sex with your bro's ex". He even desperately tries to find a loophole to feel better about betraying his "best friends".

Best - Got Marshall The GNB Job

How I Met Your Mother Ted, Barney and Marshall all work together at Goliath National Bank

In season 4, after Marshall falls into financial trouble following getting fired from his job, he gets quite depressed. In "The Best Burger In New York City", Barney offers him a job at Goliath National Bank.

RELATED: 12 Best Episodes of How I Met Your Mother

Barney has always looked out for Marshall's career. as he had helped him get an internship at his bank in season 1, and fit in with his coworkers in "Mosbius Designs".

Worst - Steals Ted's Stuff

In the season 2 episode, "Moving Day", after Ted and Robin decide to move in together, Barney sabotages it by stealing a moving truck with Ted's stuff and forces him to spend the entire day performing silly tasks.

Even worse, he sets up Ted's stuff as a "room" in the back of the truck and brings girls over to sleep with him. It doesn't get any weirder (or grosser) than that.

Best - Brought Lily and Marshall Back Together

In "Bachelor Party", Marshall gets angry at Barney for ruining his bachelor party and tells him he's not invited to the wedding. Lily, however, reveals to Marshall that while they were broken up, it was Barney who convinced her to come back to New York.

RELATED: How I Met Your Mother: 10 Continuity Errors Fans Didn't Notice

He hops on a plane, finds Lily and tells her if she knew what Marshall was going through she would be back in a heartbeat, and gets her a ticket to New York. It was perhaps one of the sweetest things he did.

Worst - Almost Sabotaged Ted's Job

When GNB brings in Sven, a Swedish architecture firm, to design the new headquarters, Barney has to choose between Sven and Ted. He chooses to go with Sven (who were going to build a T-Rex shaped building that shoots fire) and lies to Ted about it.

He tells Ted Bilson decided to fire Ted, and almost gets Ted fired. And all because he would get to have an office in the T-Rex's head (which, admittedly, is quite awesome, but not a reason to screw over your bro).

Best - Let Lily Stay At His Place

After Lily moves back to New York, she has to live in a crappy apartment. However, begrudgingly, he allows Lily to live with him if only to send away the girls he has one night stands with.

It was nice of Barney to help out Lily, especially since it's later revealed that he was the one who brought them together. He isn't always this nice so it's great to see him be so sweet.

Worst - Insults Lily's Play and Tries To Get Revenge

After Lily invites everyone to her play, Barney laughingly tells her he won't be there. Although he does show up, he tells her the play sucked and he's just being honest. Pretty terrible thing for a friend to do.

Not only that, but he also devises a 3-hour play designed to torture the others, just to prove his point. Amazingly, Lily is still nice to him and decides to sit through more of his play, he just keeps on annoying them.

Best - Gave Ted a Chance To Build His First Skyscraper

After his project got scrapped, Ted was fired from GNB. However, after the project gets greenlit, Barney gets Ted back on board to temporarily leave his teaching job and work for GNB.

RELATED: How I Met Your Mother: 5 Funniest Ted Quotes (& 5 Most Heartbreaking)

Thus, Ted gets to create his first building in his career as an architect, all thanks to Barney. It was Barney who had vouched for Ted during the first time the project was started, in season 4.

Worst - Forced Marshall to Get a Job He Hated

After getting an internship at Barney's bank, he decides not to continue with a job there, as he wanted to be an environmental lawyer. However, Barney manipulates Marshall into getting a $4000 suit tailor-made.

Marshall has no choice but to accept the job in order to pay for the expensive suit (and a wedding dress Lily destroyed). It was extremely terrible of Barney to manipulate Marshall into taking a job he absolutely despises, all because of Barney.

Best - Helped Robin Stay In America

Robin Barney in How I Met Your Mother

After Robin is almost deported in "Possimpible", Barney takes on the task of making a CV for Robin to get her a job, so she can stay in the US. Although he spends most of the episode apparently goofing around, it works.

Robin gets a job offer from Channel 12 to host their morning show, and she hugs Barney for helping her. It was a pretty sweet thing to do, especially since Barney was in love with her at the time.

NEXT: 10 TV Shows For People Who Miss How I Met Your Mother