Treasure Island's Long John Silver was clearly a villain, but was sympathetic enough for Robert Louis Stevenson to allow him not only to live, but to escape with a good deal of treasure.
An escape that is explicitly viewed with a great deal of relief by the characters, albeit because it got rid of him rather cheaply, considering.
Fablehaven has The Sphinx who had a Dark and Troubled Past and simply wished never to be a slave again. He also knew the Demon Prison would eventually fall and tried to speed things up and release the demons on his own terms. However, so many people got killed because of him, and the people who he intended to help rightfully hate him for it, and then he gets A Fate Worse Than Death at the end. Even after he's revealed to be playing both sides,he's still Affably Evil at the most.
Terry Pratchett's Lord Vetinari is essentially a Bond villain made good, with deathtraps and a lap animal (a dog, though, not a cat), but he is more sympathetic than other villains of the series and is shown to be an effective leader, wanting the best for his city. He is also fully aware of this, and explains it at length to then-Captain Vimes. In short, he is an Evil Overlord who happens to be a Reasonable Authority Figure. In no book is he actually an antagonist, although sometimes his schemes result in problems for other characters.
In a true Pet the Dog moment, it's revealed in the last two books that Vetinari's dog, Wuffles, had, at some point, passed away, and (according to gossip from the palace) every week, Vetinari pays a visit to Wuffles' grave in the palace grounds and leaves a dog biscuit there.
In Piers Anthony's Incarnations of Immortality series, various Anthropomorphic Personifications are actually offices, called Incarnations, that have been held by a series of human souls. The Big Bad of the first five books is Satan, the Incarnation of Evil, who is trying to take ultimate power from God, the Incarnation of Good, while the other Incarnations try to thwart his plans. The sixth book tells Satan's side of the story. Satan discovers that God hasn't been doing his job properly, instead, preferring to do nothing but admire his own greatness. As a result of God's negligence, many souls aren't going to the afterlife they deserve. The only way Satan can fix this is to either find a way to force God to retire, or to gain ultimate power himself by causing the population of Hell to exceed that of Heaven--and, needless to say, the other Incarnations aren't very helpful. At the end of the seventh book, the governments of the mortal world impeach God, allowing his replacement to begin cleaning up the mess the previous one left behind in alliance with Satan.
It helps that, as in Incarnation, "Satan" is really a nice but flawed guy named Parry, who managed to kill the previous Satan almost by accident. This let him take the office, and prevented a more qualified (read: actually evil) candidate from being given the position.
Chronos was also the only incarnation that acted nicely to him, so in tricking him, Satan ruined his friendship with that Chronos and his successors (well, Predecessors, but it's a complicated story).
He prevents it out of a friendship with the Jewish God. Not only that, but one of his first acts after he assumes the office of Satan (which, in turn, is because his wife was murdered) is to spare Poland from the Black Plague, because of a girl that reminded him of said dead wife. Of course, he was the one that started the plague in the first place, but it still counts.
He also spares Italy from the Black Plague in time for the Renaissance.
Gentleman Johnnie Marcone of The Dresden Files plays this trope to a tee. Despite being an illustrious crime boss and a self-confessed professional monster, his organization of the Chicago underworld has served to actually decrease and civilize crime. He's also helped (or sought the help of) protagonist Harry Dresden far more than he has opposed him. Marcone also has very strict rules regarding criminal enterprises that exploit children operating in his town (i.e. DON'T) and, at one point in Small Favor, after enduring a week's torture at the hands of the Denarians, he silently refuses to be rescued first before Harry and the Knights have freed the Archive, a twelve-year-old girl, and then shelters her with his own body while escaping.
His motivation behind no kids is "Persephone", a girl that was shot in an attempt on Marcone's life. The girl fell into a coma. The guy that shot her vanished.
At the climax of White Night, Harry even convinces Marcone to help evacuate the noncombatants who are being savaged by the ghouls by simply telling him that there were people that needed saving, and he was the only one who could do so.
The only thing that stops Marcone from crossing the line into being an Anti-Hero is the fact that he indulges in so much evil off-page and the only time he helps Harry is when they have a mutual enemy. Marcone has outright said that the only reason he hasn't put out a hit on Harry is because he figures that it's only a matter of time before one of Harry's other enemies does the job for him.
This was in direct response to Harry saying that, eventually, he will take Marcone out, but he was far down his to-do list.
Lash, the copy of the fallen angel Lasciel created to tempt Harry into a Deal with the Devil, also fits this trope. Over the course of the three books she's present in, she becomes increasingly more sympathetic until she ultimately suffers death by redemption.
Lara may also fit this trope, given all the times she's helped Harry, as well as her Freudian Excuse (she was repeatedly raped by her father before spiritually castrating him).
Kumori, who is only a necromancer because she wants to have a world where no one needs to die, spent some of her powers literally keeping death from claiming a gun downed man until the paramedics could stabilize him, and after the hero refused to join with them, asked him to leave the fight since her master would have no problems killing him.
Jarlaxle of R.A. Salvatore's Drizzt novels leads a band of amoral mercenaries, switches sides at the drop of of a pimp's hat, depending on who pays better, thrives in the twisted city of Menzoberranzan, aids the Always Chaotic Evil antagonists in their goal to kill Drizzt/take over Mithral Hall, and steals an artifact of tremendous power with the explicit intent of using it to further his goals. He was also close friends with Drizzt's (mostly moral) father, does not even entertain the thought of raping a woman he finds attractive who is quite definitely under his power, engineers the escape and survival of Drizzt from certain (eventual) death, shows mercy on enemies whom he thinks may be useful, has never murdered anyone the reader is aware of (killed in battle or self-defense, yes), and seems genuinely interested in redeeming, or, at least, reforming, the stone-cold assassin Artemis Entreri. When that fails, he instead teams up with the bloodthirsty maniac Athrogate, who, for all his antiheroic sociopathy, has a fascinating quirk in attempting to rhyme everything he says.
It's arguable if his reformation attempt failed; Artemis certainly seems more even-keeled than he was in Menzoberranzan, and although he realized the influence of the (lightly mind-screwing) flute, he didn't seem like killing people was his Thing anymore. The only reason Jarlaxle might consider the project to have failed is that Artemis got tired of being manipulated and went off on his own. And for whatever it's worth, Jarlaxle seems to consider Artemis and Athrogate Not So Different.
Let's also not forget that his theft of the artifact was doubly evil from a certain point of view, seeing as the artifact was sentient and pure evil and was known for mind-controlling even incredibly strong-willed people, and takes divine intervention to destroy. Based off the novels (especially the newer series featuring Jarlaxle as the lead character), Jarlaxle is incredibly resourceful and has enough magic trinkets to be borderline invincible. If an Always Chaotic Evil entity gained control of his mind, there's no telling what havoc could be wrought (and almost was wrought during the time he possessed the artifact, he's not as strong as he thinks he is) upon the multiverse. Artemis Entreri, the assassin Jarlaxle was 'reforming', prevented said havoc from happening.
And Artemis Enteri himself, the cold-blooded assassin who's killed more bad guys than Regis (a main protagonist). Artemis kills two mooks in the first scene to show us that he's evil, then only kills bad guys from that point on.
Obould Many-Arrows. Not a nice guy. Waged a bloody war against the heroes, but was doing it largely for (from his perspective) noble reasons - trying to elevate his people from savage cavemen into actual civilization. Also, when he fights Drizzt, he does it face to face and fairly, while Drizzt himself pulls a whole lot of dirty tricks.
One of the reasons Chinese novelist Jin Yong is considered such a great writer is because he never makes his characters evil for the sake of it, such as the case of the entire antagonistic cast of The Heaven Sword and Dragon Saber, in which they are all provided with understandable motivations, albeit couple with less than honorable m.o.
In the last Dark Tower book, the narrator admits that it's easy to pity Mordred Deschain--but warns us not to get too close.
Unless the author's being sarcastic...
Milton's portrayal of Lucifer in Paradise Lost is often argued to be this way. Milton tells the story of the fall of mankind in the style of a classical epic, and has Satan dress himself up as a tragic hero. Satan plays the role so well that many readers insist that he really is the hero he pretends to be. Critics such as William Blake commented that Milton was "of the devil's party without knowing it." Others, such as Stanley Fish, argue that Satan's rhetoric is supposed to be persuasive, so the reader understands the allure of sin.
This has caused the most epic Broken Base in literary history. Satan, though obviously bad, does bring up a few considerable grievances in a rational way.
Mertil tyl Loesp, in Matter by Iain Banks, starts off as a classic, power-hungry, regicidal villain and presumed Big Bad, perfectly happy to order a genocide simply to tarnish the King's reputation. He later becomes a far more sympathetic and conflicted character, who consciously changes his mind, considers war to be a last resort, and genuinely wants to come to an agreement with Prince Oramen, who begins to suspect what really happened to his dad. He wavers between Villain and Anti Villain through much of the book, but sadly, it doesn't matter, as he and the prince are both suddenly and horribly killed by the real Big Bad's dramatic, cityfucking entrance.
Anomander Rake from Steven Erikson's Malazan Book of the Fallen initially appears as a menacing antagonist, but is gradually revealed as one of the more heroic characters of the series. Same goes for Cotillion.
Joe Keller of Arthur Miller's All My Sons is a warm, likable, friendly fellow who genuinely loves his son and his wife. He also deliberately sold defective parts to the Airforce that got 21 pilots killed and framed his partner for it. Eventually, his justifications get broken down and he kills himself offstage at the end of the show.
The titular character of Dexter is a serial killer who kills serial killers. But he has been shown to have compassion for his sister's neuroses, as well as genuine affection and protective instincts for his girlfriend Rita and her children. He's also pretty protective of his friendly coworkers.
Clarence Potter from Harry Turtledove's eleven-books-and-counting Alternate History Timeline 191 series. His three-decade love-hate relationship with Jake Featherston, the Adolf Hitler Expy, goes to the extent that he attempts to kill him at one point (but ends up saving his life). He eventually begins to warm up to Featherston because he feels Featherston has revitalized the CSA. All of his actions are for the good of the CSA, and not the evil Freedom Party, and after the war, he tells a young man whose rants remind him of Featherston to forget the hate. He eventually ascends to Magnificent Bastard and Karma Houdini status by personally destroying Philadelphia with a nuclear weapon.
He's more of an out and out villain. He only opposes the Party because he doesn't want to hand his country over to a man he knows is nuts. He's supportive of the Population Reduction, and masterminded some of the worst atrocities of the war.
There's no virtue in wanting to protect your country from the damage an insane leader could do? At one point, he attempts to assassinate Featherston for the good of the Confederacy, even though he knows he will not survive the attempt. While he does support the Population Reduction (as, it should be noted, do most Confederate whites), he plays no part in it; if he had, he would have been so charged by the War Crimes Tribunal, who, it should be noted, specifically acquit him of atrocity, saying he acted only as a soldier would do.
Grand Admiral Thrawn wants to crush the New Republic (which he insists on calling the Rebellion). He wants to unite the galaxy so that it capitulates to a single rule--The Empire. He plans to let an insane Dark Jedi attempt to convert Luke, Leia, and Leia's children into weapons for the Empire's use. And he does it...because he knows that something horrible, powerful, and truly evil is coming, and that only by standing united and using everything at its disposal will the galaxy have a chance, so if some people must die or some freedoms must be sacrificed, so be it. Better that than extinction.
This was, however, a retcon: originally, he just wanted to re-establish the Empire, and run it along more efficient (and SLIGHTLY more pleasant) lines. Though they hinted at it as early as 1997 in the Hand of Thrawn books, with his base in the Unknown Regions, part of something vaster he'd set up, intended to watch for any of a hundred threats that would make one's blood freeze. They only made it official in Outbound Flight, written after the New Jedi Order series (completed in 2003), which featured the invasion of the Yuuzhan Vong. He is, after all, a Magnificent Bastard.
The New Republic is shown to be so screwed up that a large number of fans either disown swathes of the EU or are extremely pro-Imperial. Seriously, their incompetence is staggering...more people get killed in one battle than all the atrocities done by Palpatine!
Pellaeon, Thrawn's understudy, mostly served as the viewpoint character for the readers to see Thrawn through. In later books, he's picked up on some of his boss's tactics and is distinctly non-evil, though, of course, very Imperial. He was behind the Imperial Remnant realizing that they were outmatched and making peace with the Republic, after which point he really couldn't be called the villain at all, bad NJO garden metaphors notwithstanding.
Many examples in A Song of Ice and Fire, considering the rampant moral ambiguity, but especially Jaime Lannister (when not wearing his Jerkass mask.)
Stannis walks a fine line between this and Anti-Hero. His two main advisors each represent one of these aspects, Davos the heroic side of him and Melisandre the villainous (though Melisandre is an Anti-Villain herself).
Nicola Ceaucescu from Paul Park's Roumania series. She actually becomes more interesting than the protagonist Miranda, who is basically a standard teenage fantasy heroine except not stunningly beautiful. Nicola (who was named after a real-life Romanian dictator, who is also referenced in a fictional book within the book, in a mindbending bit of meta) is beautiful and charming, and believes that her political manipulations are all for the good of her country. She is not all that competent as a villain, since she tends to be impulsive, melodramatic, and over-emotional, with a stereotypical "artistic" temperament. She commits acts of evil like kidnapping and murdering the good guys and sacrificing men who love her, and then cries about it afterward. While her attempts at political intrigue and sorcery turn out badly, she is described as a brilliant artist on the stage, and is able to skillfully manipulate others with her beauty, charm, and acting abilities. While Miranda is described as not all that great-looking, Nicola is a famous beauty who can make men give up their lives for her even when they know she is evil, reinforcing the trope that Evil is Sexy. Nicola also has a sympathetic backstory as the daughter of a rural prostitute who ran away from home when she was very young, and lived on the streets before becoming a famous actress and luring a baron into marriage. She also has an autistic son, who was taken from her and forcibly institutionalized. She reveals a maternal streak towards her young henchman, Kevin Markasev, in addition to her son, although she eventually makes Kevin martyr himself and honors him by making him a Romanian national hero. She gets lots of sympathy from the entire country when she writes and performs a tragic opera based on her own life, which gets a standing ovation and is eventually performed by others all over the world. However, she gets killed right after her performance, and although her ghost returns to possess the heroine, she is eventually consigned to a gloomy afterlife. She's more of a fabulous theatrical diva than a Magnificent Bastard, in spite of her manipulative nature.
Clara Rinker from the books Certain Prey and Mortal Prey, part of the Prey mystery series by John Sandford. She was such a popular character that she was brought back for a second book. While Carmel Loan, the client who she became friends with after performing a hit for her, was a total sociopath, Clara was quite likable. Clara has a sympathetic backstory as a teen runaway who suffered sexual abuse, and became a professional hitwoman after a mobster found out she killed a rapist. She gets even more sympathy in the second book, as she sought revenge on the men who killed her fiance and shot her in the stomach, causing her to lose her unborn baby. Later on, the FBI take her mentally ill little brother into custody in order to get her to turn herself in. When he panics and commits suicide in jail, she loses the only person she had left in the world. She is also kind of a Magnificent Bastard, as she outsmarts the hero, Lucas Davenport (who is supposed to be a genius), as well as the FBI, with elaborate schemes to take out FBI agents and the Mafia bosses who double crossed her. In person, she's actually very down-to-earth, friendly, and personable, and is described as looking like a "cute, perky ex-cheerleader type". The chapters that describe her career, how she carefully planned out her hits and got away with them, and how she set up a legitimate business with the money she made are the most interesting parts of the book. Davenport is actually attracted to her and flirts with her a bit, and does sympathize with her difficult life. Eventually, Clara seems to go over the edge and become reckless after her brother dies, and she is eventually killed by the FBI. She is part of a trend where many female anti-villains often have to have some kind of history of abuse to make them more sympathetic, and often meet a tragic end instead of getting away with their crimes.
Inspector Javert from Les Misérables is an honest policeman who truly believes he is doing the right thing in pursuing the fugitive Jean Valjean. He simply has a naive, idealized view of the law and justice, and can't conceive of the idea that someone convicted of a crime could also be an essentially good person. After Valjean has him at his mercy but spares his life, he can't handle the idea that his lifelong belief in justice is flawed, and kills himself. The musical adaptation makes this especially clear, as the character's signature song, "Stars", in which he affirms that he will never stop until Valjean is brought to justice, could easily be mistaken as a hero's song if you don't know who it's about.
Pretty much any version of the The Phantom of the Opera beyond the original novel (and that one movie * shudder*) turns the titular character at least into this if they don't outright turn him into the protagonist of the story.
This is largely down to revisionism: Charles Dickens clearly saw Fagin as a Complete Monster who corrupted vulnerable children, arranged for the arrest and execution of his accomplices to avoid sharing his loot, and orchestrated the murder of Nancy after her Heel Face Turn. Most adaptations, worried that this comes across as anti-semitic (possibly unintentionally, since reprints in Dickens' lifetime removed most of the references to Fagin being a Jew), portray him as someone forced into crime by being made a second-class citizen, or even a loveable rogue, and remove his more "evil" acts.
Nagarak in Karen Miller's Godspeaker Trilogy is the head priest of a Religion of Evil and a dour, grim fanatic who frightens his own priests...and who sees Hekat as the bloodthirsty bitch she really is. Fortunately for him, Hekat fears the wrath of their god too much (not to mention, considers him too unimportant) to try and kill him. And then he finds out that she had sex with the godspeaker Vortka, itself an abomination in their religion, and passed the child off as that of her in-reality sterile/spermatically deformed husband. She promptly lays him out with a divine curse of her own and rapes him to produce a second child capable of wielding the Power Crystal she has found...but, conveniently, he dies from the curse, unlike Vortka, who was merely left infertile.
In Honor Harrington, Rob S. Pierre of The Haven Commitee of Public Safety. He took over from the Legislaturists sincerely planning reform and then realized that his country was so deep in a hole that the only way out was to keep digging.
Maedhros and Maglor from The Silmarillion. Because of their Oath, they killed many innocent people; however, both regretted their acts and tried to make amends for it, even attempting to forswear the Oath at various times. Maedhros was rather more diplomatic than the rest of his brothers, and he tried to save Dior's sons and avoid attacking Sirion; Maglor fostered Elrond and Elros.
Gollum from The Lord of the Rings. Sure, he looks evil, but by the third book, most readers see him as more pathetic than anything.
Gale Wynand in The Fountainhead, made more tragic in that, towards the end of the book, he tries to reform, fails, and knows that he has failed.
The lieutenant in The Power and The Glory says he wants to "speak from his heart"...but he also says that he'll be speaking "from the end of a gun". For the people, of course.
Brandon Sanderson gives us the Anti-Villain Hrathen in his book Elantris. Hrathen is a warrior monk of the militant Shu-Dereth religion who comes to the country of Arelon to convert its populace. Why? At first, it seems it's just because he believes that his religion is the right one. Then you find out what fate he was sparing them from by having them converted. He was saving their lives, and that was his motivation.
Also, by the end of the Mistborn trilogy, it becomes obvious that the Lord Ruler was this. He took power to stop an Omnicidal Maniac from getting loose and destroying the world, and many of his more evil acts were the result of said Omnicidal Maniac constantly assaulting his psyche over a thousand years, slowly driving him insane.
In the Sword of Truth series, where nearly every villain is a Complete Monster, the conflicted, guilt-stricken, ultimately well intentioned Sister Nicci can easily come across as this.
Vicar Rhobair Duchairn becomes this starting in the second book of the Safehold series. Originally as sinister a minister as the rest of the Church of God Awaiting's leadership, he begins to rediscover his personal faith. In the third book, he warns a Reformist group that the fanatic Grand Inquisitor Clyntahn has found out about them; an act which helps to at least somewhat reduce the damage Clyntahn does when he acts. In the fourth book, he uses his position as the Church's treasurer to fully fund Church-run hospitals, soup kitchens, orphanages, and schools. The only reason he doesn't act more openly against Clyntahn's excesses is because he's perfectly aware that he (and, more importantly, his family) will merely be added to the list victims without accomplishing anything.
Jacqueline Carey's 'Banewrecker' and 'Godslayer' consist pretty much entirely of deconstructions of classic high fantasy villains, from the Big Bad and The Dragon right through the ranks.
Stragos from the second Gentleman Bastard book could be seen as this. While clearly a wicked man, he was fairly reasonable, and his ultimate fate was somewhat unfair given that much less sympathetic characters in the series got off more easily.
The Captain in Brom's The Child Thief. While the other Flesh Eaters are out to destroy Avalon through a combination of religious fanaticism and insanity caused by the island, he's the Only Sane Man who is motivated simply by a desire to return home, and risks his life more than once to protect Daniel after the latter's Face Heel Turn.
Captain Nemo is one of the classic anti-villains: the protagonists' captor but also their guide to a fantastic new world, with a murderous hatred for imperialism but also boundless compassion for the downtrodden, driven by rage but also by intellectual passions; a scientist, a cult leader, an explorer, a terrorist. And we never find out why. Until the sequel.
Jefferson Hope from Arthur Conan Doyle's Sherlock Holmes novella A Study in Scarlet. Murdered two Mormon ex-suitors who forced marriage upon the love of his life, one for killing her father and the other for breaking her heart in a depressing, almost literal sense. Subsequently died of a debilitating heart condition, which he gained by pursuing them ruthlessly over two continents for several years, after being captured by Scotland Yard and Holmes. Died peacefully knowing he had his revenge.
The TIE fighter pilot Qorl from the Young Jedi Knights series fits pretty well into this trope throughout the first story arc. Shot down during the Battle of Yavin and left stranded in the jungles of Yavin IV for decades, his loyalty to the Empire never wavered. However, after his TIE is unintentionally and then forcibly repaired by the Solo twins and their friends, and even outfitted with a hyperdrive, he leaves at once to seek out the remnants of the Empire, and takes up with a Dark Jedi upstart with grand visions named Brakiss. It doesn't take Qorl long to realize that most of these new Imperials lack the dedication and discipline of the men that he served with, and slowly loses his fanatical loyalty over the course of the books. Finally, when one of his most headstrong pilots breaks out of formation during the big battle at Yavin, ignoring reprimands and disobeying orders to return in order to gun down a helpless supply ship, Qorl flies after him and blasts him out of the sky, saving the supply ship. Not long after, he's shot down for a second time and crash lands on Yavin IV, where he decides to spend the rest of his years, after becoming disillusioned with what remained of the Empire.
Lestat in The Vampire Chronicles: Interview with the Vampire. He's controlling, egotistic, selfish, and proud; he also proves to be Claudia's main obstacle to freedom and Louis goes between tolerating him and flat-out hating him. But at the same time, he's easily the most fascinating character in the story and his attitude sets him apart from other actual antagonists encountered later.
Goosebumps is known for its black and white morality with the antagonists ranging from Complete Monster to somewhat sympathetic villain. However, in the first of the series, Welcome to Dead House, one of the living dead children, Karen Somerset (and her TV adaptation incarnation Karen Thurston), is one of the series' few anti-villains. She would rather just be Amanda and Josh's friend if she could, but in order to stay alive, they have to prey on the living. Karen is the only one of the living dead to thank Amanda at the end (either for freeing them from their Fate Worse Than Death or being her friend while she could).