Sen. John McCain (R-AZ), who died of brain cancer last Saturday at the age of 81, was perhaps the strongest moral voice against torture in all of American politics — yet it was not an untainted voice.

His willingness to compromise his principles for the sake of politics at the height of the post-9/11 torture debate substantially weakened its power and ultimately tarnished his moral legacy.

McCain was brutally tortured by the North Vietnamese during the five and a half years he spent in captivity as a prisoner of war, from 1967 to 1973. The experience not only shaped his own personal views on both the immorality and the ineffectiveness of torture but also endowed him with a level of credibility and moral authority on the subject that few others could match.

When it came to light that in the wake of the 9/11 terrorist attacks, George W. Bush’s administration had authorized the use of torture on detainees, McCain, then a powerful Republican senator, took a stand that few others in his party would.

He forcefully spoke out against the use of waterboarding and other so-called “enhanced interrogation techniques” when the Bush administration and other Republicans tried to argue they weren’t torture. “It is not a complicated procedure. It is torture,” he said of waterboarding.

But when it came time to fight for actual legislation to force the Bush administration’s hand and ban the use of these methods once and for all, McCain was far less courageous. Rather than stick to his principles, he sold them out for politics — and effectively allowed the Bush administration to continue torturing people, and to get away with it scot-free.

Here’s the story of how McCain, one of the most vocal opponents of torture, capitulated for political gain right when his voice was needed the most — and why his later attempts to atone for his sins was too little, too late.

How McCain’s experience in Vietnam shaped his views on torture

McCain was a US Navy pilot during the Vietnam War. On October 26, 1967, his plane was shot down during a bombing mission over Hanoi. He ejected, breaking both arms and his right leg in the process, and parachuted down into a lake, where he was rescued by North Vietnamese villagers.

His captors sent him to Hanoi’s notorious Hỏa Lò Prison, nicknamed the “Hanoi Hilton,” where he was held for five and a half years.

For two of those years, he was kept in solitary confinement. In an unflinching first-person account of his experience that he wrote just two months after returning home, McCain described what it was like:

I was not allowed to see or talk to or communicate with any of my fellow prisoners. My room was fairly decent-sized — I’d say it was about 10 by 10. The door was solid. There were no windows. The only ventilation came from two small holes at the top in the ceiling, about 6 inches by 4 inches. The roof was tin and it got hot as hell in there. The room was kind of dim — night and day — but they always kept on a small light bulb, so they could observe me. I was in that place for two years.

He also detailed the physical and psychological abuse he suffered for two years during his captivity:

They bounced me from pillar to post, kicking and laughing and scratching. After a few hours of that, ropes were put on me and I sat that night bound with ropes. Then I was taken to a small room. ... For the next four days, I was beaten every two to three hours by different guards. My left arm was broken again and my ribs were cracked. They wanted a statement saying that I was sorry for the crimes that I had committed against North Vietnamese people and that I was grateful for the treatment that I had received from them. [...] I held out for four days. Finally, I reached the lowest point of my 5½ years in North Vietnam. I was at the point of suicide, because I saw that I was reaching the end of my rope. I said, O.K., I’ll write for them.

He broke. He signed a statement confessing that he was a “black criminal” and an “air pirate,” among other things.

“I felt just terrible about it,” he recalled. “I kept saying to myself, ‘Oh, God, I really didn’t have any choice.’ I had learned what we all learned over there: Every man has his breaking point. I had reached mine.”

That lesson — that torture would eventually make a person willing to confess to anything, whether it was true or not — was one he wouldn’t soon forget.

When he returned home to America in 1973, the then-36-year-old McCain was greeted as a war hero. He met President Richard Nixon. He became a celebrity. And soon after, he launched a political career that would take him to the highest levels of power in the US government.

McCain spoke out forcefully against torture — but capitulated when push came to shove

On November 1, 2005, the Washington Post published a damning article revealing the existence of a secret worldwide detention and interrogation program run by the CIA.

Less than a month later, McCain pushed through an amendment to the 2006 Defense Authorization Bill that restricted US military interrogators to only using methods listed in the US Army Field Manual on Intelligence Interrogation.

That excluded all those “enhanced interrogation techniques” like waterboarding, sleep deprivation, forced stress positions, electric shock, and the other forms of torture that the administration had been so fond of using on detainees.

McCain sold it as a major victory against torture.

“We’ve sent a message to the world that the United States is not like the terrorists. We have no grief for them, but what we are is a nation that upholds values and standards of behavior and treatment of all people, no matter how evil or bad they are,” he said at the time.

What the bill conveniently left out, however, was anything about restricting CIA interrogators to using only Army Field Manual-approved techniques. And since it was the CIA — and not the military — that was torturing detainees as a matter of official policy, that loophole rendered the bill essentially meaningless.

It turns out that McCain’s bill had initially called for restricting all US personnel, including the CIA, to just the Army Field Manual-approved techniques.

But as CNN reported at the time, the Bush White House balked at that, claiming that “the bill would otherwise limit presidential ability to protect Americans from a terrorist attack.” The president threatened to veto the bill unless it included an exemption for the CIA.

McCain resisted adding in such an exemption. But he compromised: The final bill that was signed into law banned all US personnel from engaging in “cruel, inhuman, and degrading treatment” of detainees — yet it only explicitly restricted the military to the Field Manual techniques.

And since the Bush administration had long been arguing that waterboarding and the other methods didn’t count as “cruel, inhuman, and degrading treatment,” the CIA was therefore free to keep using them.

McCain admitted a few years later that the 2005 bill “deliberately excluded the CIA” and “allowed the CIA to retain the capacity to employ alternative interrogation techniques.”

Alternative interrogation techniques. Like waterboarding. Which he says is torture.

But that wasn’t all.

McCain — under pressure from the White House — also added in language that included legal protections for US government personnel who had engaged in “the authorized interrogation of a terrorist suspect.”

In other words, people who were just following orders they believed to be lawful when they tortured detainees could use that as a legal defense, and the government would provide them with legal counsel.

(You might recognize this as the same legal defense some Nazis tried to use at the Nuremberg war crimes trials after World War II — a legal defense the Allied forces rejected.)

In 2008, McCain, who was then running to be the Republican nominee for president, got a second chance.

That year, Sen. Dianne Feinstein (D-CA) proposed an amendment to restrict CIA interrogators to only using the techniques approved in the Army Field Manual. Once again, the Bush administration fought back, threatening to veto it.

The morning the bill came up for a vote in the Senate, McCain again called waterboarding “torture and illegal.” It seemed that he would finally stand up for his principles and join Feinstein in trying to stop the use of waterboarding and other torture methods once and for all.

But when the vote was called later that afternoon, McCain voted against the bill, saying that he still was against torture but believed the CIA should have access to more interrogation techniques than those in the Army Field Manual. (Remember, he once felt fine limiting CIA officers to those techniques; his original 2006 torture ban did so before it was watered down.)

When it still passed despite his “no” vote, he called on President Bush to veto it.

Less than a month later, President Bush publicly endorsed McCain as the GOP nominee for president in a ceremony in the Rose Garden. Three days later, Bush vetoed the bill.

McCain’s attempt at redemption was too little, too late

When President Donald Trump announced veteran CIA officer Gina Haspel as his pick to be the next director of the CIA earlier this year, McCain voiced concern over her role in the agency’s torture program during the Bush administration.

Haspel oversaw one of the Bush administration’s most notorious “black sites” — secret prisons the CIA set up around the world to hold and torture suspected terrorists away from the prying eyes of lawyers, human rights groups, and the American public — in Thailand.

She was also directly involved in the destruction of nearly 100 videotapes documenting the CIA’s brutal interrogation and torture of two prisoners, Abu Zubaydah and Abd al-Rahim al-Nashiri, at that black site.

CIA operatives there subjected Zubaydah and al-Nashiri to waterboarding, “walling” (slamming them repeatedly into walls), sleep deprivation, nudity, and being held in confined spaces (including a wooden box the size of a coffin) for hours at a time.

Haspel didn’t officially take charge of the black site until after Zubaydah’s interrogation was over. But she was in charge during al-Nashiri’s interrogation.

When Trump announced Haspel’s nomination, though McCain was in the hospital thousands of miles away in Arizona undergoing treatment for brain cancer, he penned a letter to Haspel asking her to explain in detail her exact role in the CIA’s “enhanced interrogation” program.

“Over the course of your career with the intelligence community, you have served in positions of responsibility that have intersected with the CIA’s program of so-called ‘enhanced interrogation techniques,’” McCain wrote. He continued:

These techniques included the practice of waterboarding, forced nudity and humiliation, facial and abdominal slapping, dietary manipulation, stress positions, cramped confinement, striking, and more than 48 hours of sleep deprivation. We now know that these techniques not only failed to deliver actionable intelligence, but actually produced false and misleading information. Most importantly, the use of torture compromised our values, stained our national honor, and threatened our historical reputation.

He then provided a list of 12 highly specific questions that he asked her to provide answers to in writing, including “Did you ever impose, direct, or oversee the use of ‘enhanced interrogation techniques,’ including the use of waterboarding.”

It’s unclear whether she ever provided those written answers to McCain, but she did have the opportunity to address those same questions during her confirmation hearing before the Senate Intelligence Committee. McCain was still in Arizona undergoing medical treatment; he did not attend the hearing in person.

But he still heard what she had to say. And her answers did not assuage his concerns. After her testimony, McCain issued a statement urging his fellow senators to vote against her nomination.

“I believe Gina Haspel is a patriot who loves our country and has devoted her professional life to its service and defense,” he wrote. “However, Ms. Haspel’s role in overseeing the use of torture by Americans is disturbing. Her refusal to acknowledge torture’s immorality is disqualifying.”

The Senate voted 54 to 45 to confirm her anyway.

If things had gone a little differently, Haspel could have ended up sitting behind bars instead of in the director’s chair at CIA headquarters.

But in 2006, McCain co-authored the Military Commissions Act. As he recounted later, he and his co-authors “wrote into the legislation that no one who used or approved the use of these interrogation techniques before its enactment should be prosecuted.”

In other words, people like Gina Haspel.

In April 2009, the Obama administration followed McCain’s advice, announcing that it would not seek to prosecute CIA officers who had tortured people, as long as they had acted in accordance with the rules laid out by the Bush administration Justice Department.

McCain supported the decision.

“We need to put this behind us,” he told CBS’s Face the Nation shortly after the announcement. “We need to move forward. … We need a united nation, not a divided one.”