Basically the opposite of an anti-hero. While the anti-hero often fights on the protagonist's team, but with selfish motives, the anti-villain plays a villain's game, but for what's at least in their eyes a noble cause. They may be personally more noble or heroic than an anti-hero but the means to achieve their ends are often considered immoral, unjust, sometimes even evil. Sometimes, they may simply be a villain with gentlemanly qualities or a code of honor or some sense of justice. Anti-villains will occasionally side with their rivals (usually the protagonist) if a greater threat than themselves comes or it is in both of their best interests. Oftentimes, if they do join the protagonists, they are distrusted. Often also considered "grey" characters due to their moral ambiguity. It is possible to be both an anti-villain and anti-hero at the same time, depending on the character's goal and their methods of attaining it.
Examples of popular anti-villains include Magneto, Ozymandias from Watchmen, Eric Finch, Benjamin Linus, General Thaddeus "Thunderbolt" Ross from the Incredible Hulk comics, the Jigsaw Killer, Francis Hummel, Kane from Command & Conquer, The Operative from the film Serenity, Nagato from the Naruto series, Loki from the 2011 adaptation of the Thor comics, and the Imposter Dan from Dan Vs.. Despite this, there are some villains that do have good intentions but carry them out in a vicious manner which can make them Complete Monsters. An example of this would be Sentinel Prime from Transformers: Dark of the Moon.