Cortana, in the final Cut Scene of the original Halo, though it's clear from her tone of voice that she's trying to convince herself and the Master Chief, not stating her actual feelings.
In Halo 3, the Sangheili Shipmaster Rtas 'Vadum decides to completely incinerate a Flood-infected portion of Africa, a decision to which Fleet Admiral Lord Terrence Hood initially reacts with hostility, but he is forced to realize that there was nothing else to do.
Rtas 'Vadum: "A Flood army, a Gravemind, has you in its sights - you barely survived a small contamination."
Lord Hood: "And you, Shipmaster, just glassed half a continent! Maybe the Flood isn't all I should be worried about."
Rtas 'Vadum: "One single Flood spore can destroy a species. Were it not for the Arbiter's counsel, I would have glassed your entire planet!"
The Forerunners took some quite morally questionable actions during their tenure as the supreme civilization in the galaxy, but pretty much everyone (in game and out) agrees that firing the Halo Array and killing everything in the galaxy 100,000 years ago was a justified move, given that otherwise the Flood would have overrun everything. And the Forerunners did take precautions to re-seed life in the galaxy afterward.
In Halo 4, this is how Dr. Halsey justifies the Spartan project.
Used often in Assassin's Creed I, during the personal conversations between Altair and his Templar victims. Actually said by both sides, with Altair explaining that he has to kill the Templars for the sake of the Holy Land, and the Templars justifying their own heinous crimes.
Subverted more humorously in Lost Odyssey; Jansen Friedh tells Queen Ming, "I had to do what I had to do back there," and then admits that what he "had to do" was pretty much "sit there and let you save me."
Mass Effect gives you the option to justify your actions this way several times, especially if you chose the Renegade path. Notably, a Paragon Shepard, when pushed toward this sort of action by those around her/him, will make it clear that this is a weak justification for making supposedly "hard" choices in order to avoid difficult actions to ensure a better outcome.
The DLC "Bring Down the Sky" really hammers this home, and also if you pick the renegade option, get the bad guy, then afterwards if you pick a paragon dialogue choice, Shepard says something along the lines of "If I have to see her face every night, I can live with that.".
That is, of course, right after the villain calls you out:
Balak: You could have saved them. Who's the real terrorist here?
Shepard: You. But you're dead. *gunshot*
Mordin claims this for his work on upgrading the genophage. While he claims it's the best option he still feels horrendous guilt for his actions.
In the DLCLair of the Shadow Broker, Asari spectre, Tela Vasir, has a building bombed in an attempt to kill Liara T'Soni for the Shadow Broker while killing many innocents. If Shepard calls her out on this she says that she did what Spectres are supposed to do, the dirty work that can't be public knowledge. She also gives an excellent Shut Up, Kirk! speech alongside this, claiming her work with the Broker is no different than how Shepard is working with Cerberus.
In The Arrival DLC after Shepard destroys an ENTIRE SOLAR SYSTEM, killing over 300,000 batarians (s/he does this whether you're Paragon or Renegade) s/he defends the decision to Admiral Hackett who after a few minutes concedes that s/he had no other choice. He says that this will not stop the fallout and s/he will be put to trial for the deaths and war will likely come with the batarians.
In Mass Effect 3, you will hear the words "Those were desperate times." a lot when anyone mentions the Rachni War and the following Krogan Rebellion in the presence of Turians or Salarians.
Mordin: Had to be me. Someone else might have gotten it wrong.
When confronting a batarian who accuses Shepard of terrorism because of his/her destruction of the Bahak system, Shepard admits that s/he felt (and still feels) great guilt about it but still claims that it needed to be done.
The Charm outcome of the Admiral Zaal'Koris rescue mission in 3. The Admiral takes a very admirable The Men First approach and insists you rescue his men and leave him behind, but at that stage - unless you imported a bad save, or no save at all - you need him, in person, up on the bridge of a quarian ship in order to save the maximum number of lives, and with the Charm option you explain that to him. He accepts your logic, even though he's still not particularly pleased.
Red Alert 3 has the President of the United States say "Well, since you don't have the guts to do what needs to be done, I'm gonna wipe those Soviets off the face of the Earth myself! And you can't stop me! If my heart stops beating, the weapon fires!"
Faldio from Valkyria Chronicles justifies his shooting of Alicia to activate her Valkyria powers as needed to save Gallia. Unlike most examples of this trope, he felt guilty after he had a chance to think about his actions which led to his his Heroic Sacrifice at the Marmota.
Jaina Proudmoore says this in response to expelling the Sunreavers from Dalaran after finding out that Garrosh used the city's portal network to steal the Divine Bell from Darnassus.
In order to change his own destiny, Cid Raines in Final Fantasy XIII chose to oppose and kill the party, as it was originally his focus as a l'Cie to help them. This was an attempt to make himself somewhat human again, and it should be noted that he held no ill-will towards the party whilst doing so.
In most of the Myst games, there is an antagonist who goes into a monologue like this, most notably Gehn at the end of Riven and Escher at the end of Myst V.
In Tactics Ogre, if your player goes down the Law route, in which you kill a bunch of innocent people, this will be your response to people like Vice, who challenge your methods and cynical view.
In Dragon Age: Origins, if the main character asks Alistair if the Grey Wardens are like heroes, Alistair responds that the Wardens do whatever is necessary, implying that that includes some pretty unheroic stuff. Depending on your decisions, a ruthless yet well-meaning warden may find themselves using this justification a lot.
Anders uses this as justification for blowing up the Chantry in Dragon Age II.
Unknown Pan-Asian Coallition leader(s) from Battlefield 2142 are guilty of this trope. Their world was turning into Crapsack World thanks to new ice age. And only warm place left is the Africa, which is being prepared as warm hidey-place for Europian Union (and possibly also for USA). PAC launched an unprovocked ad merciless attack to conquer Africa for itself. But from their point of view, it was thing of survival of their nations, and PAC are not considered as bad guys by any means in the game. They might have been even on good terms with EU before, but did what they had to do for their nations.
And EU in the end did the same by kicking them out of Africa to freeze.
King Logan of Fable III. He was a ruthless tyrant who opressed his people and brutally exploited them to maximize the profits of his kingdom. It later turns out that he was doing all of that to build up an army to defend the kingdom against an inevitable attack by a monstrous horde of darkness incarnate. What's a few years of misery under his tyranic rule if the alternative is the death of all life, right? Well, no. By putting in some effort the player can prove Logan wrong by turning the kingdom into a prosperous utopia all while defending it from the attack all the same.
Kouin in Eien no Aselia uses this as a justification for his actions. He has to do what he has to do in order to save Kyouko, who has been devoured by her sword, Void.
In Phoenix Wright: Ace Attorney, Lana Skye has this attitude about forging evidence to help convict serial killer Joe Darke. It turns out that she's actually motivated to protect her younger sister Ema from being framed by Gant.
By extension, Phoenix Wright forging evidence in Apollo Justice just to find the truth largely because the real incriminating evidence had been removed. Taking down the person who destroyed his career and by extension removed said incriminating evidence, Kristoph Gavin, was an unintended bonus on his part.
In Bastion, the kid needs to destroy the petrified remains of other children who were hit by the calamity to get to a warp gate.
In Metroid: Other M, we learn that, when Samus was a federation soldier, Adam sacrificed his brother, Ian, to ensure that everyone onboard the ship he was commanding didn't die. Later he sacrificed himself to ensure that Samus didn't get herself killed going into Sector Zero.
In Spec Ops: The Line, the eponymous line is crossed several times by several people who invariably fall back on this as an excuse. A major theme in the game is that people who use this justification are largely deluding themselves, including Captain Martin Walker, the protagonist himself, who starts actually having delusions, and Colonel John Konrad, who killed himself when he couldn't convince himself of it anymore.
In Duel Savior DestinyMuriel Sheerfield is trying to kill the Messiah despite the legends because she knows that the actual Messiah awakening would be a very bad thing along the lines of an end of the world situation.
In Knights Of The Old Republic II, the player can choose this attitude for the Jedi Exile when talking about the Mandalorian Wars. Kreia claims that this is also why Revan turned to the Dark Side and started the Jedi Civil War, because he had to protect the Galaxy from a threat that the Republic couldn't handle.
Little Busters: Kyousuke is a sympathetic example in Refrain. He feels completely terrible that his actions in the previous timeline caused Rin so much damage, which he never intended. However, he is still convinced that Rin and Riki absolutely need to get stronger if they're going to survive the events of the future and he's still determined to do whatever is necessary to achieve that.
The bright, colourful and friendly Exiles of WildStar have done some terrible things to survive in a galaxy controlled by their worst enemies, the Dominion.