Characters doing the shady thing... and it works

This is pretty much what happens in Woody Allen’s Crimes and Misdemeanors to the character played by Martin Landau. His mistress is going to go to his wife, so he hires a hitman to kill her, and it works out. He’s never caught.

Later in the film, he tells a friend how, his entire childhood he was told there was a god who would reward good and punish bad. And “this guy he knows” (him) does this really terrible thing, and is never punished, and says about his story “That’s the chilling part.”

The scene where he is talked into hiring the hitman pretty much fulfills the OP’s requirements. Landau-- his character is Judah Rosenthal-- isn’t too hot on the idea of a hitman at first, but he gets talked into it pretty easily by some friend or vague relative (it’s been a while since I saw the film).

Well, I can recall a few episodes on ***NYPD Blue ***on which the chief pretty much told SIpowicz to go ahead and beat a confession out of a suspect who was OBVIOUSLY guilty but who hadn’t left much evidence behind.

It worked- the bad guy confessed and went to jail, and there weren’t any negative repercussions. Except that SIpowicz resented the hell out of his superirors, who acted as if they were better than him, who looked down on him, buit didn’t mind using his muscle to get what they wanted.

I remember that episode. The burglary fails, but they get the photos back by playing a con game on the photographer.

Well, in the Agatha Christie novel (and upcoming movie) ***Murder on the Orient Express, *** Hercule Poirot figures out who the killer(s) is/are. But he and the railroad director decide the victim deserved to die, and tell the police a non-existent Mafioso was the culprit.

In one TV episode, Thomas Magnum kidnaps, shoots and kills “Ivan,” a Russian spy who had been creating assassins via “Manchurian Candidate” type hypnotic methods.

There’s a Sherlock Holmes story that has this, “The Bruce Partington Plans”
Plans for a submarine are stolen and Holmes has a pretty good idea who they were sold to. He talks Watson into “a little armature burglary” over his vehement objection. They catch the bad guys and everything’s good.
The inspector on the case even chides them for it:

In one long-running subplot on ***NCIS: LA, *** Detective Deaks admits he killed a corrupt fellow cop because he feared that cop would hurt a prostitute who’d been one of Deaks’ informants.

Deaks gets away with his crime.

In the old, Fifties TV series “Superman” starring George Reeves, a couple figures out that Clark Kent is Superman and tries to blackmail him. Superman takes them and flies them to a distant, snowy mountaintop and leaves them there. They die trying to climb down.

Clark Kent is shown looking remorseful, but he HAD to have known the couple would either freeze to death on that mountain or die trying to get away. He probably rationalized that it was for a greater good.

Back when “The Good Wife” was on, this seemed to happen a lot. There’d be a way to win the case that was a bit shady, and sometimes they’d go for it. Sometimes it backfired, and there would be consequences, but more often than not they’d get away with it.

This was the entire legal career of Alan Shore on Boston Legal.

Group A has developed a weapon that will wipe out the insurgent group B.
A network of spies manages to steal the plans to the weapon with the intent of helping group B destroy the weapon. One of the spies is caught.
An ad-hoc group decides to 1) infiltrate group B and 2) rescue the spy, to 3) help deliver the stolen plans to group B.
Group B, upon receiving the stolen plans, proceeds to destroy the weapon along with 1,000’s of group A.

Group A: the Empire
Group B: the “rebellion”
Ad-hoc group: Luke, Han, Chewy, and Obi-wan
Spy: Leia

If you count “violate the Prime Directive” as a bad thing, then a whole buttload of Star Trek.

There is an episode of MASH where Hawkeye and BJ realize a commander is inept and that keeping him on the lines is leading to unnecessary casualties. Hawkeye drugs the commander’s drink, inducing symptoms that mimic appendicitis. BJ knows what’s going on and tells Hawkeye that what he’s doing is against medical ethics. (Great performance by Farrell, BTW - real moral distress without being whiney or sanctimonious.) Hawkeye says that its worth it and does the appendectomy, removing a healthy organ and sidelining the commander for the length of his campaign. BJ does not forgive Hawkeye, but he doesn’t report his conduct, either. The show leaves the morality ostensibly ambiguous.

The Brazilian movie The Man Who Copied has a main character who starts off a bit shady, peeping on an attractive young woman who lives across from him, but gets even shadier.

He finds out that the woman works in a boutique and goes in pretending to be looking for a gift for his mother. The man works at a copy shop, and decides to counterfeit a large denomination bill that belongs to his boss so he can go back and buy something from the boutique, allowing him to see the woman again. They begin dating…and the man keeps counterfeiting money. Since this movie seems like a quirky indie rom-com, one might assume that the rest of the story would involve the man’s shady behavior coming to light, the woman dumping him, and him trying to find a way to atone for it all and win her back.

Nope!

In fact, the main character and his friends become involved in increasingly serious criminal activity, and the movie essentially turns into a heist flick. And they get away with everything! All ends happily for our anti-heroes, both financially and romantically.

Allen revisited this basic premise in Match Point, only the main character commits the murder himself. He also murders an innocent third party to throw the police off. This plan works out for him just fine, thanks in no little part to luck (as the movie makes clear).

One of the few episodes I liked, because it was about BJ’s inner struggle, and Hawkeye was the foil.

A fairly grim Captain America story had our hero track down a killer who’d shot up a bar. Well, “track down” may not be quite right; acting on the idea that the obsessive shooter was specifically out to kill everyone in that bar, Cap tells the authorities to inform the media thus: one of the ostensible victims survived! This guy! Right here! See photo! Yeah, he’s in protective custody, we’re good, it’s all cool!

Because if the killer thinks “all the eggs in one basket” is the plan – that, instead of heavy police protection, the cops maximized secrecy by sequestering Desmond alone at a hunting cabin in the middle of nowhere – then maybe that killer will show up to finish the job, right? And to truly sell that dang-you-ferreted-it-out story, they really do escort one bundled-up guy there and leave him to fend for himself…

Anyhow, in the midst of all this Cap takes a moment to reflect on how he genuinely hates to mislead the press – and how the guy he’s impersonating may have family members who’ll suffer more because of this deception. Cap has pangs about these shenanigans, is my point. But the moment passes and our straight-ahead hero goes through with it anyway, ambushing the would-be ambusher for the win.

Hell, in Enterprise season three Archer has Enterprise commit actual piracy to continue his mission.