US Senator John McCain, the son and grandson of four-star admirals, was bred for combat. He endured more than five years of imprisonment and torture by the North Vietnamese as a young naval officer and went on to battle foes on the left and the right in Washington, driven throughout by a code of honour that both defined and haunted him.

Sen McCain, 81, died on 25 August at his ranch near Sedona, Arizona, his office announced in a statement. The senator was diagnosed last July with a brain tumour, and his family announced this week that he was discontinuing medical treatment.

During three decades of representing Arizona in the Senate, he ran twice unsuccessfully for president. He lost a bitter primary campaign to George W Bush and the Republican establishment in 2000. He then came back to win the nomination in 2008, only to be defeated in the general election by Barack Obama, a charismatic Illinois Democrat who had served less than one term as a senator.

A man who seemed his truest self when outraged, Sen McCain revelled in going up against orthodoxy. The word “maverick” practically became a part of his name.

Sen McCain regularly struck at the canons of his party. He ran against the GOP grain by advocating campaign finance reform, liberalised immigration laws and a ban on the CIA’s use of “enhanced interrogation techniques” – widely condemned as torture – against terrorism suspects.

To win his most recent re-election battle in 2016, for a sixth term, he positioned himself as a more conventional Republican, unsettling many in his political fan base. But in the era of president Donald Trump, he again became an outlier.

The terms of engagement between the two had been defined shortly after Mr Trump became a presidential candidate and Sen McCain commented that the celebrity real estate magnate had “fired up the crazies”. At a rally in July 2015, Mr Trump – who avoided the Vietnam draft with five deferments – spoke scornfully of Sen McCain’s military bona fides: “He was a war hero because he was captured. I like people who weren’t captured.”

Once Mr Trump was in office, Sen McCain was among his most vocal Republican critics, saying that the president had weakened the United States’ standing in the world. He also warned that the spreading investigation over Mr Trump’s ties to Russia was “reaching the point where it’s of Watergate-size and scale”.

John McCain: US Senator in pictures Show all 40 1 /40 John McCain: US Senator in pictures John McCain: US Senator in pictures John McCain - 2000 John McCain waves to crowds at The University of Portland in Oregon. McCain was campaigning for Republican nominee George W. Bush AFP/Getty John McCain: US Senator in pictures John McCain - 1967 Senator John Mccain In A Hanoi Hospital During The Vietnam War November, 1967 Getty John McCain: US Senator in pictures John McCain - 1993 John McCain, a former POW, looks at a display of personal belongings of American POWs at the joint POW/MIA archives center in the Hanoi Army Museum AFP/Getty John McCain: US Senator in pictures John McCain - 1999 Republican Senator John McCain announces his official bid for the 2000 White House in Nashua, New Hampshire. Evoking five years as a prisoner of war in Vietnam, McCain highlighted his own sacrifice and his 17-year record of public service in the US Congress AFP/Getty John McCain: US Senator in pictures John McCain - 1999 Republican presidential candidate John McCain poses with an A-4 jet -- similar to the one which he was piloting when he was shot down during the Vietnam War -- on the deck of the USS Intrepid aircraft carrier in New York. McCain, who flew off of the Intrepid during the Vietnam War, but was not on it when he was shot down, was at the Intrepid to receive the 1999 Intrepid Freedom Award AFP/Getty John McCain: US Senator in pictures John McCain - 2000 Republican presidential hopeful John McCain answers questions at a news conference in New York AFP/Getty John McCain: US Senator in pictures John McCain - 2000 US Arizona Senator and Republican Presidential hopeful John McCain smiles as he speaks on the phone during a radio show interview from his hotel room in Los Angeles AFP/Getty John McCain: US Senator in pictures John McCain - 2000 US Arizona Senator and Republican presidential hopeful John McCain reacts to cheers from the crowd after speaking in a rally at the Santa Clara University on the eve of the multi-state SuperTuesday primaries AFP/Getty John McCain: US Senator in pictures John McCain - 2000 US Senator John McCain (R-AZ) smiles as he is interviewed on WGIR-AM radio in Manchester as he campaigns to become the Republican candidate for president of the United States AFP/Getty John McCain: US Senator in pictures John McCain - 2002 John McCain on "The Tonight Show with Jay Leno" Getty John McCain: US Senator in pictures John McCain - 2004 Senator John McCain speaks at the Victor Awards in Las Vegas Getty John McCain: US Senator in pictures John McCain - 2008 US Senators Joe Lieberman, Lindsey Graham, John McCain and former senator Phil Gramm watch the Super Bowl at the Hyatt Regency Boston. McCain was leading in most polls over rival contender former Massachusetts Gov. Mitt Romney before the biggest "Super Tuesday" in American history Getty John McCain: US Senator in pictures John McCain - 2009 John McCain shakes hands with Dorothy Cross, great niece of the first African American heavyweight boxing champion John Arthur "Jack" Johnson. McCain and Peter King introduced a resolution calling on President Barack Obama to posthumously pardon Johnson, who was a victim of what is widely regarded as a racially motivated conviction in 1913 for violating a law prohibiting taking women across state lines for "immoral purposes" Getty John McCain: US Senator in pictures John McCain - 2009 John McCain delivers remarks at the John Hopkins University Paul H. Nitze School of Advanced International Studies in Washington, DC. McCain spoke on "Why Freedom Still Matters" and "Human Rights and Foreign Policy." Getty John McCain: US Senator in pictures John McCain - 2010 John McCain with veteran Richard Philippi at VFW Post #1677 during a campaign stop in Casa Grande, Arizona Getty John McCain: US Senator in pictures John McCain - 2010 Cindy and John McCain during the Western Conference finals of the NBA Playoffs between the Los Angeles Lakers and the Phoenix Suns at US Airways Center in Arizona. The Lakers defeated the Suns 111-103 Getty John McCain: US Senator in pictures John McCain - 2010 John McCain speaks to a group of supporters alongside his wife Cindy at his victory party after winning Arizona's primary election in 2010 Getty John McCain: US Senator in pictures John McCain - 2010 Senate Armed Services Committee ranking member US Sen. John McCain stands in an elevator on Capitol Hill. The US Senate is debating a the New START, Strategic Arms Reduction Treaty, and is expected to vote on it before the end of the 111th Congress's lame duck session Getty John McCain: US Senator in pictures John McCain - 2010 U2 frontman Bono and John McCain talk during the 2010 Atlantic Council awards dinner at the Ritz Carlton Hotel in Washington, DC Getty John McCain: US Senator in pictures John McCain - 2011 US Defense Secretary Leon Panetta greets ranking member John McCain before a hearing of the Senate Armed Services Committee Panetta and Chairman of the Joint Chiefs of Staff Adm. Michael Mullen testified before the committee on US strategy in Afghanistan and Iraq Getty John McCain: US Senator in pictures John McCain - 2011 US President Barack Obama speaks prior to signing the John M. Roll United States Courthouse Bill into law in the Oval Office of the White House as Homeland Security Secretary and former Arizona Governor Janet Napolitano, Senator John McCain, Chief of Staff to Rep. Gabrielle Giffords Pia Carusone, Rep. Ed Pastor, and Rep. Trent Franks look on. President Obama signed the bill to name a new federal courthouse in Yuma, Arizona, after federal Judge John M. Roll, who was gunned down during the shooting rampage in Tucson, Arizona Getty John McCain: US Senator in pictures John McCain - 2012 Republican presidential candidate and former Massachusetts Governor Mitt Romney talks with former presidential nominee US Sen. John McCain on Romney's campaign bus with Press Secretary Andrea Saul in between events near Manchester, New Hampshire. McCain announced his endorsement of Romney the day after Romney beat former US Senator Rick Santorum by only eight votes in "first in the nation" Iowa Caucuses Getty John McCain: US Senator in pictures John McCain - 2012 John McCain rides on the Senate subway after participating in a news conference on Capitol Hill. McCain joined Senate Foreign Relations Chairman John Kerry as he urged fellow Senators to approve the "Convention on the Rights of Persons with Disabilities bill, an international agreement for protecting the rights of individuals with disabilities Getty John McCain: US Senator in pictures John McCain - 2012 John McCain speaks to members of the media after a hearing on the Benghazi attack before the Select Committee on Intelligence in Washington, DC. Former Central Intelligence Agency (CIA) Director David Petraeus testified before the committee about the September 11 attacks on the American diplomatic compound in Benghazi, Libya, that killed Ambassador Christopher Stevens and three other Americans Getty John McCain: US Senator in pictures John McCain - 2012 John McCain turns to greet Ileana Ros-Lehtinen and Mario Diaz-Balart during a campaign visit to support Republican presidential candidate, former Massachusetts Gov. Mitt Romney at the Bay of Pigs Museum and Library of the 2506 Assault Brigade in the Little Havana neighborhood in Miami, Florida. McCain took the time to rally people behind Romney and to encourage them to go out and vote Getty John McCain: US Senator in pictures John McCain - 2012 John McCain speaks during an interview in his Russell Senate Office Building office on Capitol Hill. McCain said he wanted a solid NATO-Afghanistan accord sealed at a summit, ensuring critical post-2014 US involvement in the region rather than "looming international abandonment." AFP/Getty John McCain: US Senator in pictures John McCain - 2013 US Secretary of State Hillary Clinton and Sen. John McCain joke and embrace before Sen. John Kerry's confirmation hearing before the Senate Foreign Relations Committee to become the next Secretary of State in the Hart Senate Office Building on Capitol Hill Getty John McCain: US Senator in pictures John McCain - 2013 John McCain testifies before a Senate Commerce, Science and Transportation Committee hearing on the state of video, on Capitol Hill in Washington, DC. The committee discussed unbundling cable services and the impact of changing technology, among other topics Getty John McCain: US Senator in pictures John McCain - 2013 John McCain, Meghan McCain and Jimmy McCain attend "Raising McCain" Series New York Premiere at Tribeca Cinemas in New York Getty John McCain: US Senator in pictures John McCain - 2013 Prince Harry is accompanied by US Senator John McCain as he tours a Senate photo exhibit on landmines and unexploded ordnances in the Rotunda of Russell Senate Office Building in Washington, DC. Prince Harry was in the US on a week long visit AFP/Getty John McCain: US Senator in pictures John McCain - 2013 US Senator John McCain speaks during a mass rally of the opposition in Independence Square in Kiev. McCain told more than 200,000 EU supporters rallying in Kiev that Washington backed their desire for European integration. "To all Ukraine, America stands with you," he called out to the cheering crowd. "The free world is with you, America is with you, I am with you... Ukraine will make Europe better and Europe will make Ukraine better." AFP/Getty John McCain: US Senator in pictures John McCain - 2013 US Senators Lindsey Graham and John McCain meet with Israeli Prime Minister Benjamin Netanyahu in Jerusalem, Israel GPO/Getty John McCain: US Senator in pictures John McCain - 2014 John McCain hugs Debbie Valle after speaking at a forum at the Burton Barr Central Library in Phoenix, Arizona. McCain met with Arizona Veterans to discuss mismanagement of Veterans Affairs Getty John McCain: US Senator in pictures John McCain - 2014 John McCain and wife Cindy attend a MLB game between the Arizona Diamondbacks and the Los Angeles Dodgers at Chase Field in Phoenix, Arizona. Getty John McCain: US Senator in pictures PHOENIX, AZ - NOVEMBER 08: Sen. John McCain (R-AZ), center, and his wife Cindy (R) greet supporters after casting their vote at the Mountain View Christian Church polling place on November 8, 2016 in Phoenix, Arizona. Throughout the country, millions of Americans are casting their votes today for either Hillary Clinton or Donald Trump to become the 45th president of the United States. (Photo by Ralph Freso/Getty Images) Ralph Freso Getty Images John McCain: US Senator in pictures John McCain - 2015 WASHINGTON, DC - MAY 05: Sen. John McCain (L) (R-AZ) and Sir Elton John, Founder, Elton John AIDS Foundation, pose for a photo before an Elton John AIDS Foundation and The ONE Campaign hosted reception on global HIV/AIDS funding at the U.S. Capitol Visitor Center on May 5, 2015 in Washington, DC. (Photo by Paul Morigi/Getty Images for EJAF) Paul Morigi Getty/EJAF John McCain: US Senator in pictures John McCain - 2017 Senator Amy Klobuchar takes a selfie with Senator Chris Van Hollen, Senator John McCain and Senator Bernie Sanders on the West Front of the US Capitol in Washington, DC at Donal Trump's inauguration ceremony. He became the 45th president of the United States Getty John McCain: US Senator in pictures John McCain - 2017 Sen. John McCain gives a thumbs up to well wishers as he gets into his car at the US Capitol. McCain was recently diagnosed with brain cancer but returned on the day the Senate is holding a key procedural vote on US President Donald Trump's effort to repeal and replace the Affordable Care Act Getty John McCain: US Senator in pictures John McCain - 2017 US Army Chief of Staff Gen. Mark A. Milley greets Sen. John McCain during a special Twilight Tattoo performance at Fort Myer in Arlington, Virginia. McCain was honored with the Outstanding Civilian Service Medal for over 63 years of dedicated service to the nation and the US Navy Getty John McCain: US Senator in pictures John McCain - 2017 John McCain arrives at Capitol Hill. Donald Trump's tax reform plan has overcome pockets of resistance within Republican ranks, US senators said, setting up a vote that could provide the president with his first major legislative victory."We have the votes," Senate Majority Leader Mitch McConnell told reporters as he entered the chamber AFP/Getty

Sen McCain’s most dramatic break with Mr Trump came nine days after the Arizona senator announced on 19 July, 2017, that he had been diagnosed with brain cancer. He returned to the Senate chamber, an incision from surgery still fresh above his left eye, and turned thumbs down on a GOP plan to replace the Affordable Care Act. Sen McCain’s no vote, along with those of two other Republicans, sent his party’s signature legislative goal hurtling towards oblivion.

In both of his own presidential races, Sen McCain had dubbed his campaign bus the “Straight Talk Express”. To the delight of reporters who travelled with him in 2000, he was accessible and unfiltered, a scrappy underdog who delighted in upsetting the Republican order.

“He was always ready for the next experience, the next fight. Not just ready, but impatient for it,” said his longtime aide Mark Salter, who co-authored more than a half-dozen books with the senator, including three memoirs, the final of which included a stinging critique of Mr Trump. “He took enjoyment from fighting, not winning or losing, as long as he believed he was fighting for a cause worth the trouble.”

So broad and party bending was his appeal that Senate Democrats in 2001 quietly tried to persuade him to become one of them. In 2004, Democratic presidential nominee John Kerry, a senate colleague who later became Obama’s secretary of state, considered offering Sen McCain the second spot on his ticket.

Sen McCain’s 2008 presidential campaign turned out to be a far more conventional operation than his first bid for the White House. He stuck to his talking points and came to represent the status quo that he had once promised to topple.

One move, however, would come to be regarded as a reckless political gambit. Sen McCain picked as his vice presidential running mate the little known, thinly vetted governor of Alaska, Sarah Palin.

Her well-received convention speech initially gave the sagging Republican nominee a lift, and her independent streak reinforced Sen McCain’s message and reputation. Looking back on the decision in 2012, Sen McCain said he had been looking for “a way to galvanize and energize our campaign”.

But Ms Palin’s performance in interviews and on the stump sowed doubts about whether she was prepared to be next in line for the presidency and, by Election Day, polls indicated that she had become a drag on his candidacy.

When he acted like an ordinary politician, trimming principles in the cause of ambition and expedience, it was all the more jarring because of the standard he had set. In the years that followed, a question often asked was: Which is the real John McCain?

He represented the end of an era during which the nation looked at wartime military experience as practically mandatory for those who aspire to high office. “McCain was part of the tradition of being able to say, ‘I did public service when I was young,’ “ historian Douglas Brinkley said.

John McCain stops supporter saying Obama is 'an Arab'

Sen McCain, who rose to become chairman of the Armed Services Committee, was among the Republicans’ most hawkish leaders on military matters and foreign affairs.

It was a mindset that came, in part, from his conviction that the Vietnam War, in which he had suffered grievously, was a noble and winnable endeavour. The real failure, he believed, was that of a spineless political class.

During the Iraq War, often compared to Vietnam, Sen McCain was an early and ardent proponent of a 2007 “surge” of troops. President Bush ultimately adopted that strategy, and it was widely credited with stabilising Iraq, albeit temporarily.

Sen. McCain was also a persistent critic of Obama’s foreign policy.

“The demand for our leadership in the world has never been greater. People don’t want less of America – they want more,” Sen McCain said in 2012. “Everywhere I go in the world, people tell me that they still have faith in America. What they want to know is whether we still have faith in ourselves.”

***

John Sidney McCain III was born 29 August 1936, in the Panama Canal Zone and into a family whose military lineage included an ancestor who served as an aide to Gen George Washington during the Revolutionary War.

He was named for the first father and son in Navy history to become full admirals: John S ”Slew” McCain Sr, a top Pacific-theatre commander in World War II, and John S McCain Jr, commander for all armed forces in the Pacific during the Vietnam War.

The middle of three children, Sen McCain manifested his famously hot temper early: As a toddler, he would hold his breath until he blacked out. His tantrums were so severe that a Navy doctor advised his father and mother, the former Roberta Wright, to drop him, fully clothed, into a bathtub of icy water at the first sign of an outburst.

After transient early years spent mostly at military bases, he graduated in 1954 from a Virginia boarding school, Episcopal High School in Alexandria. Following his father’s and grandfather’s path, and his parents’ often-stated expectations, Sen McCain then enrolled at the US Naval Academy, which he later recalled as “a place I belonged at but dreaded”.

At Annapolis, he rebelled against the hazing and the regulations and racked up so many demerits that he was at risk of expulsion. (That, too, was something of a family tradition.) As Sen McCain often boasted later in life, he graduated fifth from the bottom of the 899-member class of 1958.

From there, he headed to Pensacola, Florida, to be trained as a Navy pilot and continue the rowdy existence of his days at the academy.

One girlfriend at the time was a stripper who went by the professional name Marie, the Flame of Florida. Sen McCain recalled taking her as his date to a party of young officers and their mannerly wives. Marie became bored, drew a switchblade from her purse, popped it open and cleaned her fingernails.

He did a stint as a flight instructor in Meridian, Mississippi, at McCain Field, named for his grandfather. It was there, Sen McCain recalled, that he matured and became dedicated to distinguishing himself as a pilot.

“As a boy and young man, I may have pretended not to be affected by the family history, but my studied indifference was a transparent mask to those who knew me well,” the senator wrote in a 1999 memoir of his early life, “Faith of My Fathers,” co-authored by Mr Salter. “As it was for my forebears, my family’s history was my pride.”

Sen McCain also became involved in a serious romance, with Carol Shepp of Philadelphia, whom he had known since his days at the academy. They wed in July 1965, and he soon adopted her two sons from a previous marriage, Douglas and Andrew. The couple later had a daughter, Sidney.

Sen McCain requested and got orders to do a Vietnam combat tour, joining a squadron on the supercarrier Forrestal in the Tonkin Gulf. On 29 July, 1967, having flown five uneventful bombing runs over North Vietnam, he was preparing for takeoff when a missile accidentally fired from a nearby fighter struck the fuel tank of his A-4 Skyhawk, Sen McCain wrote in his memoir. It set off explosions and a fire that killed 134 crewmen, destroyed more than 20 planes and disabled the ship so severely that it took two years to repair.

His own injuries being relatively – and miraculously – minor, Sen McCain, then a lieutenant commander, volunteered for dangerous duty on the undermanned carrier Oriskany. He joined a squadron nicknamed the Saints that was known for its daring; that year, one third of its pilots would be killed or captured.

***

On 26 October, 1967, Sen McCain was on his 23rd mission and his first attack on the enemy capital, Hanoi. He dove his A-4 on a thermal power plant near a lake in the centre of the city.

As he released his bombs on the target, a Russian-made missile the size of a telephone pole blew off his right wing. The lieutenant commander pulled his ejection-seat handle and was knocked unconscious by the force as he was hurled from the plane. He came to when he hit the lake, where a mob of Vietnamese had gathered.

With both arms and his right knee broken, he was dragged from the lake, beaten with a rifle butt and stabbed in the foot with a bayonet. Then Sen McCain was taken to the French-built prison that American POWs had dubbed the “Hanoi Hilton”.

So began five-and-a-half years of torture and imprisonment, nearly half of it spent in solitary confinement. During that time, his only means of communicating with other prisoners was by tapping out the alphabet through the walls.

At first, his family was told that he was probably dead. The front page of The New York Times carried a headline: Adm McCain’s Son, Forrestal Survivor, Is Missing in Raid.

The North Vietnamese, however, perceived that there was propaganda value in the prisoner. They called him the “crown prince” and assigned a cellmate to nurse him back to health. As brutal as his treatment was, Sen McCain later said, prisoners who lacked his celebrity endured worse.

Shortly before his father assumed command of the war in the Pacific in 1968, Sen McCain was offered early release. He refused because it would have been a violation of the Navy code of conduct, which prohibited him from accepting freedom before those who had been held longer.

“I knew that every prisoner the Vietnamese tried to break, those who had arrived before me and those who would come after me, would be taunted with the story of how an admiral’s son had gone home early, a lucky beneficiary of America’s class-conscious society,” Sen McCain recalled. “I knew that my release would add to the suffering of men who were already straining to keep faith with their country.”

His lowest point came after extensive beatings that broke his left arm again and cracked his ribs. Ultimately, he agreed to sign a vague, stilted confession that said he had committed what his captors called “black crimes.”

“I still wince when I recall wondering if my father had heard of my disgrace,” Sen McCain wrote. “The Vietnamese had broken the prisoner they called the ‘Crown Prince,’ and I knew they had done it to hurt the man they believed to be a king.”

In March 1973, nearly two months after the Paris peace accords were signed, Sen McCain and the other prisoners were released in four increments, in the order in which they had been captured. He was 36 years old and emaciated.

The effects of his injuries lingered for the rest of his life: Sen McCain was unable to lift his arms enough to comb his own prematurely gray hair, could only shrug off his suit jacket and walked with a stiff-legged gait.

***

Sen McCain had hoped to remain in the Navy, but it became clear that his disabilities would limit his prospects for advancement.

In the meantime, he found himself drawn towards the civilian world of politics – and it towards him. Hobbling on crutches in his dress-white service uniform, he shook president Richard M Nixon’s hand. Sen McCain also struck up a friendship with then-California Gov Ronald Reagan, who invited the former POW to speak at an annual prayer breakfast in Sacramento.

He developed a network of political contacts while working in the Navy’s legislative affairs operation in the late 1970s. His office on the first floor of the Russell Senate Office Building was a popular late-afternoon socializing spot for younger senators and their staffs.

Sen McCain’s marriage, meanwhile, frayed and fell apart. That was not an unusual story among returning Vietnam POWs, and in his case, the dissolution was aggravated by his infidelities.

While he and his wife were separated, Sen McCain visited Hawaii, where he met Cindy Hensley, the daughter of a wealthy Arizona beer distributor. A few months after his divorce became final in 1980, he married Ms Hensley. Then-Se. William Cohen, R-Maine, later to be a defence secretary, was his best man, and then-Sen. Gary Hart, D-Colo., a future presidential contender, was an usher.

The couple had three children: Meghan McCain, who became a media personality and blogger, and sons Jimmy McCain and Jack McCain, both of whom served in the military. They also adopted a daughter, Bridget McCain, whom Cindy had met while visiting an orphanage in Bangladesh.

Besides his mother, his wife and seven children, survivors include a brother, Joseph McCain of Washington; a sister, Jean McCain Morgan of Annapolis, Maryland; and five grandchildren.

Sen McCain retired from the Navy at the rank of captain and moved to Arizona in 1981, with an eye towards running for Congress. The opportunity presented itself the following January when a longtime Republican congressman, John Rhodes, announced his retirement. That same day, the McCains bought a house in Rhodes’s Phoenix district, and John McCain was soon in a race against three other candidates.

He was called an opportunist and a carpetbagger – accusations he dispatched with a single answer at a candidate forum.

“I wish I could have had the luxury, like you, of growing up and spending my entire life in a nice place like the 1st District of Arizona, but I was doing other things,” he replied to one critic. “As a matter of fact, when I think about it now, the place I lived longest in my life was Hanoi.”

He won the primary by six points and breezed through the general election. Four years later, in 1986, he was elected in a landslide to the Senate, replacing the retiring Barry Goldwater, one of the most influential conservative politicians of the 20th century.

John McCain was a Capitol Hill celebrity from the moment he was elected to the House.

In many areas, he was a reliably conservative voice and vote. But from the beginning, he showed what became a trademark streak of independence. He called for the withdrawal of Marines from Lebanon in 1983 after a terrorist bombing left 241 US service members dead; he voted to override President Reagan’s veto of sanctions against the apartheid regime of South Africa in 1986.

And – surprisingly to many – as a member of the Senate, he worked to normalize relations with Vietnam.

Sen McCain crusaded against pork-barrel spending, the practice by which lawmakers direct taxpayer money to projects in their districts. He was also the only Republican to vote against the Telecommunications Act of 1996, a deregulation measure he said had been “written by every [special] interest in the world except the consumers.”

Acclaimed by the media, he was not popular in the Senate. Many of his colleagues were put off by his certitude.

“John puts things in terms of black and white, right and wrong,” then-Sen Tim Hutchinson, R-Ark., told The Washington Post in 2000. “If you disagree with him, you’re wrong. He doesn’t see that there could be legitimate differences of opinion that deserve respect.”

One of the greatest setbacks for Sen. McCain, who had styled himself an idealist and a reformer, came in 1989, when his name became associated with a scandal. He and four other senators – all Democrats – were accused of trying to pressure federal bank regulators to back off an investigation of Charles Keating Jr, a high-living Arizona businessman whose savings and loan collapsed and cost taxpayers more than $3bn (£2.3bn).

Over the years, Keating had contributed heavily to Sen. McCain’s House and Senate campaigns. The senator’s family had taken at least nine trips, at Keating’s expense, to the Bahamas, where Keating had a luxurious vacation estate.

Sen McCain and the four Democrats – Alan Cranston of California, Dennis DeConcini of Arizona, John Glenn of Ohio and Donald Riegle Jr. of Michigan, all of whom had also benefited from Keating’s largesse – became known as the “Keating Five”.

The Senate Ethics Committee finally determined that Sen McCain had not done anything more serious than showing “poor judgment” by attending two meetings with the regulators and the four other senators. It was the lightest reprimand the committee gave in connection with the scandal. The others were rebuked but were not charged with crimes.

Sen McCain felt that he bore a permanent taint. “It will be on my tombstone, something that will always be with me, something that will always be in my biography,” he said, “and deservedly so”.

The experience also lit the fire for what would become his signature issue and biggest legislative achievement: an overhaul of campaign finance laws. Sen. McCain teamed up with one of the Senate’s most liberal members, Russell Feingold, D-Wis., to author a measure that called for the most dramatic change to the system since the post-Watergate reforms of 1974.

It took them more than seven years to get the legislation through. The 2002 law’s main thrust was to ban unlimited, unregulated “soft money” donations to parties, which were used as a means of skirting the contribution limits to individual candidates.

In less than a decade, however, the Supreme Court’s Citizens United v. Federal Election Commission decision opened the money floodgate and led to the rise of super PACs, which can spend unlimited sums, as long as they do not coordinate directly with candidates. Sen McCain called it “the worst decision of the United States Supreme Court in the 21st century.”

***

When Sen McCain announced in September 1999 that he was running for the Republican nomination for president, it was yet another assault on the political establishment, which had put its chips on then-Texas Gov. Bush, the son of a former president.

“In truth, I had had the ambition for a long time. It had been a vague aspiration,” he later wrote. “It had been there, in the back of my mind, for years, as if it were simply a symptom of my natural restlessness. Life is forward motion for me.”

He ran as a truth-telling reformer, held a record-setting 114 town hall meetings in New Hampshire (while effectively ignoring the Iowa caucuses) and pulled off a stunning 18-point victory over Bush in the Granite State’s first-in-the-nation primary. But his campaign ran aground in South Carolina in what came to be regarded as the nastiest primary in memory.

Sen. McCain was the target of rumours: that he had fathered a black child (twisting the facts about his dark-skinned adopted daughter); that his wife had a drug habit (she acknowledged having been addicted to painkillers and stealing them from a charity she ran); that his years as a POW had left him brainwashed and insane.

One of his regrets, he later said, was getting tangled up in South Carolina’s emotional debate over flying the Confederate flag at the capitol in Columbia. After describing the banner as “a symbol of racism and slavery,” Sen. McCain bowed to the pleas of his panicked strategists and issued a statement saying he could “understand both sides” of the question.

Later, he wrote that he regretted not having told the truth, which was that he believed “the flag should be lowered forever from the staff atop South Carolina’s capitol”.

“I had not been just dishonest. I had been a coward, and I had severed my own interests from my country’s. That was what made the lie unforgivable,” he recalled. “All my heroes, fictional and real, would have been ashamed of me.”

Bush handily defeated Sen McCain in South Carolina, beginning the end of the senator’s insurgent campaign. In April, a month after he dropped out of the 2000 race, Sen McCain returned to the state and publicly apologised for having chosen “to compromise my principles. I broke my promise to always tell the truth.”

The bitterness of that campaign lingered for much of Bush’s presidency. Sen McCain was, for instance, one of only two Senate Republicans to vote against Bush’s 2001 tax cuts. He said they were fiscally irresponsible and benefited “the most fortunate among us, at the expense of middle-class Americans who most need tax relief.”

But by the time he ran again in 2008, Sen. McCain had come to terms with Bush and the Republican Party, and they with him. He not only voted to extend the tax cuts in 2006, but also advocated making them permanent.

Whereas Sen McCain had lashed out at evangelical leaders Pat Robertson and Jerry Falwell as “agents of intolerance” during his first presidential bid, he delivered the commencement address at Falwell’s Liberty University in 2006. Falwell introduced him with lavish praise, saying, “The ilk of John McCain is very scarce, very small.”

The shift rightward caused a breach with a constituency that Sen. McCain had long counted as in his corner: the media.

“Are you going into crazy base world?” comedian Jon Stewart asked Sen McCain during an appearance on Comedy Central’s “The Daily Show” a few weeks before the speech at Liberty.

“I’m afraid so,” Sen McCain deadpanned.

His campaign all but collapsed in the summer of 2007, but Sen. McCain battled back and won the nomination.

Still, he was flying into head winds in the general election. The war in Iraq, which he had supported, was unpopular, as was the Republican incumbent in the White House. Palin’s erratic, unprepared performance became a story in itself.

Most important, he was up against a Democrat who seemed tailor-made for that moment in history: Obama was better financed, ran a better campaign, had opposed the Iraq War and offered the captivating prospect of putting an African American in the White House for the first time.

Nonetheless, the race looked as if it could be close until the final weeks, when the financial system went into a meltdown. Sen McCain, so sure of himself on national security issues, seemed less than savvy at handling economic ones. Even as the crash was building into the worst economic crisis since the Great Depression, the senator declared that “the fundamentals of our economy are strong.”

Returning to Congress, Sen McCain became a frequent antagonist of the man who had defeated him for president. He contended for instance that Russian President Vladimir Putin’s 2014 invasion of Crimea was a result of “a feckless foreign policy where nobody believes in America’s strength anymore.”

When Sen McCain got the gavel of the Armed Services Committee in 2015, he told The Post that he was having more fun than at any time since his 2000 presidential campaign. That same year, he announced plans to run for a sixth term in the Senate.

Sen. McCain won handily, and in his victory speech to supporters, he predicted that campaign “might be the last”.

“Thank you one last time,” he added, “for making me the luckiest guy I know.”

In his final book, reflecting on his life as it came to an end, Sen McCain wrote: “It’s been quite a ride. I’ve known great passions, seen amazing wonders, fought in a war, and helped make a peace. I made a small place for myself in the story of America and the history of my times.”