There is always a hero and a villain, but sometimes a character blurs the line between the two. This character is called the ant-hero, a protagonist who doesn't conform to the rules and traits of the hero. An anti-hero is a hero who doesn't have heroic traits, but fights to protect the same things.
Another example of an anti-hero is when the villain has to help the hero accomplish something. This is usually done by the villain to accomplish something they want. This has been done a lot in recent stories, including Loki in Thor the Dark World, and GLaDOS helping Chell in Portal 2.