This is the attitude that the protagonists of Weiss Kreuz take toward their work as assassins. They kill criminals who are above the law in order to help protect the innocence of normal people, while acknowledging that they themselves are also criminals and murderers, and expecting to be punished for it someday. Even their voice actors, one of whom is the creator of the series, do not expect their characters to meet good ends.
Sailor Moon: Sailors Uranus and Neptune consider their actions necessary but not worthy of forgiveness. They are revealed to have pure hearts midway through.
In Gundam Wing, Treize Kushrenada and Milliardo Peacecraft start a war to show humanity just how senseless war really is. Treize actually goes so far as to commit to memory the names of every single one of his deceased pawns, to show that he doesn't take their sacrifices lightly.
Another example is the side of Gundam 00's Celestial Being represented by the Ptolemaios crew. They are fully aware of the hypocritical and outright contradictory nature of their mission statement to end war through war, with some even admitting that they make for excellent terrorists. However, it turns out that the Ptolemaois crew is played for exactly the same reason; they themselves are rendered a hypocritical foe by the very same organization for whom they supposedly work. It works out, somehow.
Lelouch, The Protagonist, openly admits that he's doing reprehensible things in pursuit of noble goals (bringing down The Empire and making the world a better place for his Morality Pet sister). This is pointed out in an early second season episode where he engages in a short Breaking Speech to Honor Before Reason Guilford about the best way to confront an overwhelming evil. In the end he has himself killed to create world peace; whilst he never explains (to the viewer) exactly why he did it, the implication is that it was as redemption for the sins he committed during the course of the series.
In the latter parts of the series after Suzaku has his Heel Realization moment he attempts to kill his benefactor for the last year, and then helps his best, and probably only, friend in the world, become evil dictator of the world, then kill him.
Itachi murdered his entire clan save for his brother Sasuke and lived out the rest of his life as a traitor hated by everyone in order to prevent a war. He planned to die by Sasuke's hand since the beginning.
Danzo considers himself this, claiming the ninja world must unite, and there's no time to do it morally.Makes sense considering he is Itachi's old boss.
Dr. Kabapu from the Excel Saga manga claims to be this by seeking to destroy all Overtechnology left behind by the Solarian civilization in order to avoid the End of the World as We Know It repeating itself. However, it conveniently puts him in a position of power in Fukuoka City and sets him against his age-old nemesis Lord Il Palazzo, so it's less than clear whether his words, or Il Palazzo's for that matter, can be trusted.
The Iscariot Organization in Hellsing. Their Badass Creed is them chanting how they will follow the disciple Judas in following God's plan through the means of sin and betrayal, and that they will march into hell to do battle with its demons when they die.
Amber in Darker than Black is leading a sort of La Résistance against The Syndicate, having learned that they're planning to kill off every single Contractor by destroying the Gate. Unfortunately, the only permanent solution for that is to have BK-201 seal the area around the Gate, which would wipe Japan off the map. Being a Contractor, she has no qualms about it, but when presented with another option, is willing to Ret Goneherself to make it work.
Light Yagami starts off this way in Death Note because he is determined to sacrifice himself for the greater good. However, less than a week later he's squeeing over his promotion to godhood. It doesn't keep him from occasionally toying with the concept of himself as selfless and self-sacrificing, though. This doubles with What You Are in the Dark, as Light carries out his actions as quickly as possible during the first five days in an attempt to do as much good as possible before he meets his horrid end. It is only after finding out that there are no consequences for using the Death Note, that he begins to turn into the egotistical Jerk Ass that he becomes.
Captain Bravo of Busou Renkin descends into this when he accepts the order to kill Kazuki before he completely Victorizes (A process they did not know could be arrested or reversed at the time). He even freely admits that this is a war crime that he will have to answer for once the war is over.
Captain Bravo: I am going to terminate Kazuki and then defeat Victor. I will do my duty as Captain Bravo, the Warrior Chief. And then, as Mamoru Sakimori, I will pay for what I have done... by ending my own life.
Necessarius from To Aru Majutsu no Index is a English Anglican organization trained to hunt down magicians using that same magic. Their proper name is even "the Church of Necessary Evil."
Paul von Oberstein from Legend of the Galactic Heroes is a Necessarily Evilstrategist who seeks to overthrow the Deadly Decadent Court of The Empire (which he belongs to), at any cost. At one point, he allows two million people to die in an atomic attack he was forewarned about, simply because having it happen would discredit the nobles and help Reinhard take control of the empire. He is fully aware that he must be Reinhard's Poisonous Friend and in many ways plays the 'lightning rod', letting the negative public opinion focus on himself instead of Reinhard.
Okiura from Kobato is pretty clearly evil. He's with the yakuza, and using threats and underhanded tactics to force his own ex-wife Sayaka to shut down the preschool she's taught at all her life to collect on a debt she inherited from her father the former owner. That's Disney evil. It's later revealed that he's afraid that the yakuza will hurt Sayaka, and has been working from the inside to buy her as much time and safety as possible. He doesn't have the authority to call off the others, and he knows if she sells the building, she'll be safe. And better he shatter her dreams than the yakuza shatter her limbs. He does his best to appear cold and villainous in an attempt to push her into selling, and accepts that while he might be saving her life, Sayaka will probably never love him again.
Emiya Kiritsugu of Fate Zero lives by this trope, although he is an extreme Anti-Hero rather than a villain. Originally he was an idealist who wanted to save everyone, but all the deaths he witnessed left him cynical and disillusioned. He lives by a harsh code of utilitarian ethics- killing the few to save the many. His ultimate goal is world peace, and he is willing to do anything to achieve it. As he himself says:
"Even if I am to carry "all the evils of this world", it won't matter. If that can save the world, then I'd gladly accept it."
He has a breakdown at the very end of the series when his attempt to destroy the Grail causes far more destruction and death, realizing that everything he did was pointless — not "necessarily" evil at all, just evil. He barely avoids falling into despair by rescuing and raising the lone survivor of the disaster: Shirou, the hero of Fate/stay night.
Mirai Nikki: This is how Yukiteru views himself, once he decides to actively take part in the Survival Game. Prior to that, the only people he killed were in direct self-defense. As he begins killing in order to win the game, he justifies it by saying that once he's become the new god, he can resurrect everyone he's killed and give them happy lives.
In the back story of GUNNM Last Order, this attitude is essentially responsible for the state of the world. Arthur, the leader of humanity After the End establishes a totalitarian dictatorship with the goal of ensuring that the catastrophe that nearly left humanity extinct doesn't happen again, mobilizing all of Earth's remaining resources to achieve spaceflight and colonize the stars. He recognizes this as evil, and potentially the wrong decision, and leaves behind a means to end the undying dictatorship he created.
Comic Books
Ozymandias in Watchmen constructs himself as Necessarily Evil in his final conversation with Dr. Manhattan, justifying murdering millions of people with his success in preventing further escalation of the Cold War and claiming 'he has made himself to feel every death'. He is never brought to justice for his acts and the comic does not judge either way, leaving the readers to make up their own minds on the subject. A throwaway comment that references the Black Freighter comic implies that, ultimately, he has availed nothing.
Alter from Y: The Last Man, after dealing with internal discord in Israel thanks to an abrupt end to their conflict with Palestine, concludes that America will suffer the same fate without an outside enemy to distract them — Naturally, that would be her. This is later revealed to be a cover for her real plan to be killed by Yorick.
In the DCU, Amanda Waller's original characterization. One storyline had the Suicide Squad being forced into disbanding. Amanda's response: hijack three of the prisoners who made up the Squad, offer them their freedom in exchange for their cooperation, brutally massacre the gang of thugs who had set in motion the disbanding (and who were preparing to release a flood of zombifying drugs onto the streets)... and then turn herself in to face trial. Going further, she refused to use her knowledge of American espionage to get a better deal, reasoning that they'd dig her out if they ever needed her again. She ended up spending a year in prison.
The ending of V For Vendetta features this trope, though it's the protagonist who realizes that he can't live in the utopia he's spent the entire book trying to birth.
In Cable & Deadpool, Cable endeavours to unite the world against a devastating enemy - himself. The idea being, with his powers spiralling out of control and becoming a threat, everyone would team up and kill him, and then feel guilt for doing so, as his public plan was to establish an island utopia. Later in the same book, he aided the revival of Apocalypse so the decimated mutant race would have an enemy to unite against.
The reason Wolverine was recruited by Iron Man & Captain America to join the New Avengers was that he would be able (and willing) to kill if necessary, whereas the rest of the team wouldn't.
Nick Fury, Marvel's resident Spy Master is often a jerkass who performs morally questionable, but necessary actions due to the grey world he lives in.
"What I do is evil. I have no illusions about it, but it must be done."
The main theme of The Dark Knight was Batman - and his perception in the eyes of Gotham City - becoming this. He hoped that Harvey Dent, Gotham's 'White Knight', would make him obsolete so no further evil of any sort would exist within Gotham.
Mr. Glass in Unbreakable has spent his entire life being Necessarily Evil and looking for someone to counterbalance him so that his world will make sense.
The death squad in Magnum Force. They kill known criminals with summary executions because to them, courts do not work.
The Controllers and Director in The Cabin In The Woods. The Controllers have become desensitized enough to run bets and enjoy some of the "entertainment" the ritual provides, though a little bit of their basic human decency still slips through, and tell their new recruit that even his training isn't enough to prepare him for the real thing. The Director is extremely, painfully aware of how evil their actions are, and regrets them deeply, but will do everything possible to see them fulfilled.
The Red Queen is this in Resident Evil, going to any lengths to prevent a T-virus outbreak.
Literal example in Wreck It Ralph; A video game only works when there's a 'bad guy' to defeat. When Ralph, the 'bad guy' of his game, isn't there, the game is declared out of order.
Vampire in Brooklyn: Eddie Murphy's vampiric antagonist kills and then impersonate an Evangelical preacher, then finds events contriving to force him into making an impromptu sermon. Given his own evil and selfish intentions, it's little surprise when he chooses the concept of Necessary Evil as his topic and sets about convincing his congregation not to be so hard on the bad guys as, without Evil for comparison, no one would know what Good was.
Literature
Emperor Ezar, in Lois McMaster Bujold's book Shards of Honor, sets up a massive interplanetary war and gets several thousand people killed, all to assassinate his son, a deranged sadist, and discredit his cronies, a batch of expansionist warmongers, thus averting the ascension of a madman to the throne and subsequent civil war.
The Wolves/Inhibitors of Alastair Reynolds' Revelation Space trilogy wipe out intelligent life any time they discover it spreading beyond its original planet. (Even they, a kind of Mechanical Lifeforms, are only intermittently sentient when necessary to reach their goals.) It eventually turns out they are trying to keep intelligence from being wiped out forever when our galaxy collides with the Andromeda galaxy several billion years in the future.
A small-scale version is the killer in The Victorian Hangman, the executioner for New York, unemployed after NY switched to the electric chair. He traveled west and continued his practice of eliminating criminals. After executing an adulterer, a thief, and a card cheat, he realized he was the only criminal left in the area.
In the Warhammer 40000 Gaunt's Ghost novel ''The Guns of Tanith' one of the Ghost's less savoury members kills an old man to keep word of their secret mission getting to the Blood Pact. Subverted by the thoughts of Hlaine Larkin in the same squad thinking 'There was quite enough unnecessary evil in the fething galaxy without deliberately adding to it'.
This is also why Vetinari set up the guild system for the thieves and assassins. He reasons that since there is going to be crime, it might as well be organized crime. In short, both guilds are allowed to steal and kill a certain amount each year, and in return they must crack down on any freelancers. In case you're wondering why someone as sharp as Havelock would trust a bunch of robbers and murderers, it's because he doesn't; since they're organized, legitimized, above-board, and Vetinari knows where they live.
This is half the reason Unseen University employs Prof. John Hicks Hix: he plays the part of the evil (but not too evil) necromancer so UU can claim a monopoly on all evil magical activities, suppressing any freelancers at will.
This is an Alternative Character Interpretation of Judas Iscariot in The Gospel of Judas, a Gnostic text dating back to the fourth century. In it, Judas is depicted as following Jesus's instructions when he turned him over to Pontius Pilate, in order to set in motion the events that lead up to Jesus's resurrection (though only according to the National Geographic translation, not to serious scholars).
Harry Potter: Snape carried this role in the latter half of the series as Dumbledore's mole in Voldemort's inner circle. He had to do Death Eater things such as kill Dumbledore himself to prove himself and maintain his cover. Dumbledore planned for that to happen because he believed it necessary.
Dumbledore: Severus... please!
The Horus Heresy novels provide us with one person who joined the Heresy not because he believed the Emperor had betrayed them, but because he knew it was side with Horus and save everyone except humanity, or side with the Emperor and screw over the entire galaxy and everyone in it: Alpharius. The Drop Site Massacre, and all other events of the Heresy, were being done in order to break the back of Chaos.
An inspirational tale that did the rounds about two captives who were being tortured into renouncing their faith. One night, the first man admits that if the tortures continue the next day, he will have no choice but to surrender. His friend spends the night mulling over whether to kill the first man so that the first man's immortal soul might remain saved - while he himself will be damned to hell for the murder - but at last realizes that it would be wrong. His choice was right, because the first man mercifully dies on his own in the morning before the torturers come.
In Daniel Suarez' Daemon Sobol's plans for a new society require him to tear down the one that currently exists, ultimately causing global economic and social chaos. In the end, it appears that his actions are justified.
In the Warhammer 40k novel Angels of Darkness, Brother - Chaplain Boreas delivers a very short speech regarding the value of human life in the grim darkness of the 41st millenia. " 'Oh, I agree that battle and sacrifice result in death,' Boreas replied with a grimace. 'I understand that we live in a brutal universe, and that amongst the unnumbered souls of the Imperium, a few million deaths are immeasurably minute. The Dark Angels have purged worlds that are beyond all attempts at redemption, and we have done it with joy for we know what we do is for the security of the future. Truly it is said a moment of laxity spawns a lifetime of heresy' ".
Varys in A Song of Ice and Fire claims himself to be this: "Why is it always the innocents who suffer most, when you High Lords play your Game of Thrones?" However, he is perhaps the most gifted intriguer and spy in the Seven Kingdoms, so his own motivations are incredibly clouded.
Ebenezar McCoy of the Dresden Files taught Harry about how magic is suppose to be about protecting life and respect for the laws of magic. Ebenezar is the Blackstaff, the only wizard on the White Council who has permission to break the seven Laws of magic, ranging from mind control to mass murder, when the "rules" are being used against the council and to prevent even worse disasters.
In the sixth book of The Saga of Darren Shan, The Vampire Prince, Kurda Smahlt and his plan turned out to be this.
In The Stormlight Archive King Taravangian sees himself this way. When called on it by his Dragon Szeth, he fully admits that he's a monster, but that he's "the monster who will save this world".
Forever Gate: Leader of the Users attempts to convince Hoodwink the gols are this trope. In a nushell this is his argument: The gols do nasty things but without them our civilization would crumble.
Live Action TV
This is how Chief of Police Unser views his arrangement with the eponymous bike gang of Sons Of Anarchy. He allows them a more or less free hand in and around Charming and they keep drugs and other gangs out.
Tigh: Which side are we on? We're on the side of the demons, Chief. We're evil men in the gardens of paradise, sent by the forces of death to spread devastation and destruction wherever we go.
UFO. Although the nature of the aliens is a mystery, their harvesting of human organs indicates they come from a Dying Race. Commander Straker suggests they view humanity not with malice but with callousness ("much as we view our food animals"). Straker later encounters a man with telepathic powers who is being controlled by the aliens. In the middle of their conversation he suddenly blurts out: "We mean no harm to the peoples of Earth. Why do you attack us? We're fighting for existence... you must understand!"
Torchwood's Captain Jack Harkness, when he's not The Ace, a Lovable Rogue, or a Chivalrous Pervert, pretty much bases his entire character around being this. The best (worst?) examples are the episodes "Small Worlds" and "End of Days", and of course, the miniseries Children of Earth.
The Shadows regard themselves as agents of evolution and the genocidal wars they wage on the galaxy as an effective form of natural selection and development drive for the Younger Races. The problem is that there never was a need for such accelerated development, and Shadows only enforce it to prove that it works.
William Edgars, who plans to use an artificial plague to institute a Final Solution on human telepaths, finds it to be a monstrous idea but the most expedient solution to what he considers an otherwise unsolvable problem.
Queen Mab from the Merlin-1998 series tries to pass herself off as this, but the other characters don't believe her, mostly due to her complete and utter amorality in the face of the pain caused by her actions. As emphasized in the novelizations, Merlin is also "necessarily magical" as he uses the magic of the Old Ways to create a society free of the Old Ways, and gradually becomes less and less welcome in the new society when the now predominantly Christian kingdom gets less tolerant of a wizard of the Old Ways.
Buffy the Vampire Slayer included lamp-shading the overlap between this and Shoot the Dog in the season 5 finale when Giles explains why he is about to kill Ben (Glory's relatively innocent human host), because Buffy won't and shouldn't have to.
In season 6 of Supernatural, Castiel becomes this after Micheal has been locked up with Lucifer, and the only remaining archangel wants to break open the cage so Lucy and Mike can finish up their big fight, or even worse, become the new God. Faced with the prospect of death, or going along with these plans, Castiel was forced to Take A Third Option that had him trying to handle the slippery slope without jumping.
Allison Taylor does this in the final season of 24 by protecting the true masterminds behind the terrorist attacks earlier in the day and allowing them to go unpunished for the actions even after learning they were behind it all in a desperate attempt to secure a peace treaty between the United States, Russia, and another country.
The Imperial Inquisition. On a whim, every fully ranked Inquisitor in the service can have any individual pressed into service, commandeer vehicles (up to and including Space Marine Battle Barges) for their use, summarily execute anyone they deem heretical, torture people indefinitely, and call down Exterminatus: the complete destruction of the biosphere of a planet, if not just blowing up the whole damn rock. Their decisions are inviolate. One of the most famous phrases ever uttered by an Inquisitor is "A plea of innocence is guilty of wasting my time. Guilty." Why is this gross extremism necessary? Because if they weren't around, the taint of Chaos would spread unchecked throughout the Imperium, and within less than a dozen generations the whole galaxy would be rendered lifeless and/or sucked into a psychic-energy-powered expy of HELL itself. So, yes, horribly evil, very necessary.
The perfect example would be Inquisitor Kryptman. He ordered the creation of a Galactic Cordon, and in the process caused hundreds of billions of deaths and more destruction than any set of events since the Horus Heresy - including the Reign of Blood, the Black Crusades, and the Armageddon Wars. He saved the galaxy, but was declared Excommunicate Traitoris for his methods.
This trope is the title of a Savage Worlds book that allows PCs to play supervillains in world where aliens had successfully killed off all the superheroes.
Theater
In Jesus Christ Superstar Judas considers his betrayal of Jesus to be this in order to keep his movement from getting out of hand and destroying the Jewish people. To a lesser extent this is also true of Caiaphas although there's also a large amount of self interest mixed in in his case.
The big twist at the end of Urinetown is that the Evil Overlord Cladwell was right the whole time and the revolution that overthrows him makes everything so much more awful than it was under his draconian rule.
Ulysses is played like this toward the end of Jon English's Paris. He was like this to an extent in the original Iliad, but it's made explicit that the wooden horse was a case of this in the musical.
Logan views his actions as these in order to fund an army and prepare Albion to deal with an Eldritch Abomination called the Crawler.
You have to be this to get the bad-karma ending, otherwise known as the one that doesn't involve everybody you know and love dying. Unless you feel like playing the Lute for ten hours or going into real estate. Have I mentioned you're the king/queen?
Kessler, the Big Bad of In Famous, Kessler is The Protagonist Cole McGrath's future self. In the future he was the world's most powerful conduit, but when the world needed him most, he vanished, following which the world got blown to hell by the real villain. Feeling guilty for not stopping it, he uses his powers to travel back in time in order to accelerate the development of the Ray Sphere, which gave him his powers, and to shape his past self into the kind of person who would be capable of saving the world by killing the only woman he ever loved and destroying half the city.
The sequel reveals that this backfired since the villainalso got his powers from the Ray Sphere. Woops. If only Kessler knew the Ray Sphere was the device that lead to the villain's creation...
Ammon Jerro in Neverwinter Nights 2. Not only does he deal with devils, and other deadly creatures of the lower planes in order to get what he needs done. True, he's trying to save all of the sword coast. But at the same time he kills his granddaughter, and several other people whom are really not all that bad. They just happen to get in his way. Though he does have a Villainous Breakdown when he realizes who Shandra was, and spends the rest of the game trying to atone for what he's done.
For the most part the Overlords are this to the world. They seem to save the world (so they can take it over) from the other (worse) evils and Fallen Heroes. Rose states that the Balance Of Good And Evil will mean that during the times when Light Is Not Good and becomes too powerful, Darkness is required to triumph.
According to the manual, Gill. Like all Street Fighter canon, it's... complicated.
Bian Zoldark and Maier Branstein in Super Robot Wars Original Generation. When they realized that the government was preparing to surrender to the coming alien invaders, they launched an attempt to Take Over the World, in order to give mankind the means to fight back against the invaders, remove those who wanted to collaborate, and finally, ensure that the heroes were strong enough to spearhead the counterattack. Tragically, a lot of their minions had different plans. Most of which involve 'kill the heroes, take their place'. Which may have been Bian and Maier's back-up plan.
Seraph Lamington in Disgaea allowed Vulcanus to run amok, and later justly but "excessively" punished Flonne for a relatively minor sin by turning her into a flower. He was however willing to, and counting on, being defeated by the protagonist. It is revealed in the good ending that he was plotting with the ghost of the Netherworld's ruler to use a Batman Gambit and force Laharl to grow up and become kinder, so they will unite both kingdoms. In the good ending, Laharl spares the Seraph's life, and he returns Flonne to life as a fallen angel (with cute bat wings and red trim), which was part of his plan all along assuming Laharl passed the Secret Test of Character - Not that that matters anymore, now that she's his right hand angel now.
Valvatorez, the protagonist of Disgaea 4, is a strange sort of Punch Clock Villain who sees his job of being an evil, human-terrorizing tyrant as a very important public service - If he isn't going to Scare 'Em Straight, who will?
Wild Arms 2 has Irving Vold Valeria, who formed both the heroes and the villains as a two-tiered plan to gather information as well as global resources in order to stop a sentientdimension from swallowing their world. The villains could use whatever tactics they wanted; and the heroes would be able to get the combined support of the world's governments who wanted them to stop the villains.
In Suikoden II, Jowy seems at first to be simply a Face Heel Turn or a Rival Turned Evil, when he betrays the city of Muse to the Highlands, assassinates the Mayor, and opens the gates to the invaders. It turns out, however, that he only did it because he knew that the only way to stop the monstrous Luca Blight, was from the inside - and so, he sold out Muse in order to gain Luca's trust, so that he could later betray him, bringing about his death at the hands of the hero. However, by the time Luca dies, Jowy has already married Luca's sister, and he thus becomes the ruler of Highland... and thus, he is responsible for the nation, and feels compelled to win the war. At the very end of the game, he is gambling on The Hero killing him, so that he can use his life-force to seal the Beast Rune that Luca unleashed earlier... whether it actually ends that way, however, depends on a few things...
In Pokemon Ruby And Sapphire, you are required to ally yourself with either Team Aqua or Team Magma (depending on which game you are playing) in order to oppose the other Team. This does not mean that the Team you are allied with isn't evil, however; they are simply not currently involved in any world-threatening plans, while the Team you are opposing is clearly doing something worse.
Claudia Wolfe from Silent Hill 3. She acts cruel and evil to the protagonist and orders the murder of her father...but Heather eventually finds her diary, which is filled with entries about how much she's sorry for having to put Heather through all this, and only feels she must do it to bring the birth of paradise for Heather and everyone... everyone, that is, except Claudia herself. She believes in Hell, by the way. That's right, Claudia believes that she deserves to go to Hell for committing the necessary evil to save everyone else, meaning she absolutely embodies this Trope. Heather stops whatever the result would have been, but Claudia's intentions are definitely well intentioned and self aware.
One possible interpretation in Knights Of The Old Republic is that Revan waged war against the Republic in order to toughen them up and force them to become more militaristic to prepare them for future conflict that Revan alone foresaw. The second game of the series has the other theory that it was to prevent societal collapse, or that it was all part of a plan to prepare for ANOTHER enemy. Which he left to find. This is supported by Kreia's question about Revan's "fall" in KOTOR 2: "Did Revan truly fall? Or did he do whatwas necessary to prepare the republic?" It is implied through the game's plot that the enemy Revan "prepared" the galaxy for were the True Sith, featured as the main baddies in the upcoming Old Republic MMO.
If you're going to bring Star Wars' Expanded Universe into this, the original Heir to the Empire trilogy portrayed Grand Admiral Thrawn as a ruthless warlord but a competent, at times even caring commander. The later books set him up as someone attempting to prepare the galaxy for invasion, which came with the Yuuzhan Vong.
Trias the Betrayer from Planescape: Torment. A fallen angel, he betrayed his kin and made a compact with the lower planes: He would cause mass acts of betrayal that would send the border town of Curst into Carceri and shift the balance of the planes towards evil. In return, he would be given control of an army of demons, which he planned to use to attack the gates of heaven themselves. Trias expected both this army and himself to be defeated, but hoped that such an act would be enough to rouse the celestials of the upper planes to take a more hands-on approach in the war against evil instead of doing what he saw as being Achilles in His Tent while evil was allowed to run rampant.
Sephiran from Fire Emblem: Radiant Dawn. Acts affable to the end, and loyal to one of the heroes even while he is fighting the others. Can't be talked out of fighting the heroes, yet is happy upon defeat.
The following pattern is pretty common in Fire Emblem, especially in the endgame of Radiant Dawn:
"I can't allow you pass" [grueling battle] "Thank you for killing me, please move onward!"
Everyone in Iji: The Tasen invade Earth because they're being hunted to extinction by the Komato and think that Earth would be a nice place to hide. The Komato general justifies his campaign by saying that the folks back home will settle for nothing less than total annihilation. Iji calls bullshit on both counts. And if you play in the standard action adventure style, they'll retort with Not So Different.
Wallachia in Melty Blood. Turns out he was trying to prevent the end of the world, but every solution he came up with just made things worse. He became a Dead Apostle in order to get the power to hopefully avert it.
Speaking of the Nasuverse, we have Emiya Kiritsugu, from Fate Zero and Fate/stay night, who is more than willing to shoulder all the evils in the world in order to save everyone. He did shoulder all the evils in the world, but didn't completely save people from them.
Yuan in Tales Of Symphonia may be this or a Well-Intentioned Extremist. It doesn't show him acting guilty for what he does, but then again, he doesn't show much emotion at all and the storyline doesn't focus on him enough to give him a chance.
Being a fairly nuanced RPG, Dragon Age: Origins allows you to behave like this in any number of situations, justifying a great deal of evil as necessary to destroy the darkspawn.
In the sequel, Anders stands out among a city of Well-Intentioned Extremists as one of the few who acknowledges that the actions taken to reach his goals are inexcusable. He doesn't blow up the Chantry because he thinks it's the right thing to do... but because things have gotten so hopeless and the stalemate between the templars and the mages has remained deadlocked for so long that he sees no other option.
Meredith verges on this a few times as well, though it swings back and forth between this and Knight Templar given the Sanity Slippage means one moment she's insisting the templars are entirely in the right, and the next she seems more regretful and willing to acknowledge some of her methods for controlling the mages are inhumane. Sometimes within the span of a few seconds.
Duke of Tales Of Vesperia is the poster boy for this trope. His Entelexeia friend Elucifur was betrayed and killed by humans right after Elucifur helped them win the Great War. When the Adephagos eventually showed up, his solution for it was to destroy it using the energy absorbed from the life force of humans, including himself, effectively wiping humanity off the face of the planet but saving every other life form. Unusually for the final boss, the party manages to talk him out of it at the end of battle and he ends up helping them.
Master Mattias in Luminous Arc 2, who seems to continue his reign of terror of killing people to fuel Rega the demon sword with their souls, after being released from being sealed by Fatima and Josie. He's actually preparing to stop the Beast Fiends at their source and sealed them away, plus the souls inside Rega will be released after it's used for the plan.
In Rockman & Forte: Challenger from the Future, R-Shadow reveals to Mega Man that the reason he's come from the future to destroy him was to stop the problems that Wily has caused at its roots by destroying all of the robots of the past.
In Jade Empire, Sagacious Zu claims that he viewed the actions of the Lotus Assassins — killing political opponents and terrorizing the citizens of the Empire — as necessary to preserve the authority of the Emperor and the stability of the Empire. When they started targeting women and children purely as punitive action against their husbands/fathers, however, it got too much for him.
In order to save the world, The Joy had to be perceived as a traitor and die by Naked Snake's hands. Needless to say, this caused some nasty emotional trauma to him.
Act 3 of The FreeSpace2modWar in Heaven has the Fedayeen faction. They view themselves as monsters and psychopaths who have no place in their relatively peaceful society, and are expected to carry out atrocities without hesitation, while still recognizing that they are atrocities. They use any means at their disposal to secure the survival of the United Earth Federation, because their defeat will (supposedly) signal the extinction of the human race, and maintain there's no room for morality when the stakes are that high. Judging from what we've seen in the story so far, they may have a point.
Many of the Renegade decisions in the Mass Effect games can come across like this.
Saren Arterius, The Dragon of Mass Effect, believes his terrible actions such as attacking a defenseless colony, researching living weapons, and betraying the Council are absolutely necessary for the future of the galaxy. Tela Vesir, a Spectre in Mass Effect 2, provides this justification for her ruthless actions such as ( bombing an office building with many civilians inside). She combines this with Not So Different and Shut Up, Kirk! if a Paragon Shepard - who is working with the terrorists of Cerberus - calls her out on it.
The titular Kamui fighters are considered this since they use the inhumane Brain Uploading technology, but they where necessary due to the ZODIAC's laying waste to the earth at the time.
Balthazar in Baldur's Gate 2: Throne of Bhaal. He is one of the Five, a group of Bhaalspawn convinced by the Big Bad to exterminate their siblings, ostensibly in exchange for a chance to serve as the lieutenants of Bhaal, the dead god of murder, when he is resurrected by the deaths of enough of his children. When you confront him it turns out he has other plans - he intends to eliminate the other members of the Five and as many Bhaalspawn he can find, the Big Bad (who is the only one who can resurrect Bhaal), and then kill himself, ensuring that Bhaal's chance to return dies with him. The player has no choice but to fight him, and he verbally regrets the player character death as a "necessity."
The plot of Shadow Hearts: Covenant does retcon the first game's antagonist Albert Simon's plans, turning him from a Well-Intentioned Extremist into something more like this trope. It turns out Simon was desperately trying to stop Rasputin - yes, that Rasputin - and the secret society Sapientes Gladio from potentially destroying humanity in their mission to take over Europe through occult means.
Also in the same comic, Klaus Wulfenbach took over Europe and rules it with an iron fist to prevent Sparks from running wild and terrorizing the populace with pointless wars. There are those who believe him to be a "mere" Well-Intentioned Extremist.
In the Thog Infinitron, the aliens that gave Thog his powers finally realize their mistake, and decide they must destroy Thog to hide their mistake, even though they admire him.)
In El Goonish Shive, Abraham is this in order to kill the spawn of the Dewitchery Diamond.
Best example: Procedure 110-Montauk, which is never described in detail, but the details we are told about*
Like the fact that all non-D-class staff have to be rotated out every two months for psychological counseling, and are permitted to subject themselves to Laser-Guided Amnesia after they've completed their assignment with SCP-231
make it clear that what they are doing is subjecting an innocent young woman to a horrifically traumatizing procedure which they must modify to be even worse if she ever becomes desensitized to it, because if they don't, she gives birth to something undisclosed which poses a serious threat to everyone in the surrounding area and possibly life as we know it. An Easter Egg hidden on the page questions how necessary this evil actually is.
She-Beast of the Whateley Universe describes the international supervillain Dr. Diabolik like this, including talking about the thousands of people who have died in his efforts to advance the human race. She may be giving him more credit than he deserves though, since she is his daughter.
Now that we have seen him attack the entire city of Cincinnati, we know the truth. She didn't give him enough credit.
Taylor of Worm is not the only example of this in the series but is certainly the most clear cut. Initially purely a mole among her villainous friends, she comes to view villainy as the best way to achieve her goals. Entirely selfless goals.
While Captain Jarvis in The Return sees himself as evil for what he does, really he is just Necessarily Evil, this doesn't really reassure him. A lot of what Willard International Consulting does could fall under this trope due to existing in a Grey and Gray Morality series.
Western Animation
In the beginning of the Woody Woodpecker short Ration Bored, Woody himself flat out admits that he is a necessary evil. Given the context under which he said that, he could have meant it as a joke.
Amanda Waller saw Cadmus as a check as against the Justice League falling from grace.
The Justice Lords. They see themselves as being able to accomplish what the Justice League cannot.
On South Park, the "Hero" noted that sometimes blowing up hospitals is for the greater good.
Wonder Man in The Avengers: Earth's Mightiest Heroes; the only reason he is acting as a member of the Masters of Evil is because their Black Magician Girl, the Enchantress, is the one casting the spell that allows him to stay alive, meaning he can only stay alive if he does what they say. Other than that, he has absolutely no interest in being a supervillain.