WASHINGTON (Reuters) - U.S. Senator John McCain, a former prisoner of war in Vietnam who ran for president in 2008 as a maverick Republican and became a prominent critic of President Donald Trump, died on Saturday. He was 81.

A senator from Arizona for more than three decades, McCain had been suffering from brain cancer since July 2017 and had not been at the U.S. Capitol this year.

He died on Saturday afternoon at his ranch in Arizona with his wife, Cindy, and other family members at his bedside.

McCain frequently battled with Trump and his family has said he did not want the president to attend his funeral.

Flags flew at half-staff at the White House on Sunday. Trump has tweeted his “deepest sympathies and respect” to McCain’s family, although he added no words of praise for McCain himself

All five living former presidents - Barack Obama, George W. Bush, Bill Clinton, George H.W. Bush and Jimmy Carter - paid tribute to McCain’s courage and character.

Cindy McCain said her husband had “passed the way he lived, on his own terms, surrounded by the people he loved, in the place he loved best.”

McCain will lie in state in the Arizona Capitol on Wednesday and in the U.S. Capitol in Washington on Friday.

There will be a memorial service at the Washington National Cathedral on Saturday, with U.S. and international leaders invited to attend, and McCain will then be buried in a private ceremony at the U.S. Naval Academy in Annapolis, Maryland, on Sunday.

AFFABLE, CANTANKEROUS

McCain’s death brings to 50 the number of Republican-held seats in the 100-member U.S. Senate, with Democrats controlling 49. Republican Arizona Governor Doug Ducey will appoint a member of his own party to succeed McCain after the funeral.

That could also give Republicans a slight edge in the battle to confirm Brett Kavanaugh to the U.S. Supreme Court because McCain had been too ill to vote this year.

Alternatively affable and cantankerous, McCain had been in the public eye since the 1960s when, as a naval aviator, he was shot down during the Vietnam War and tortured by his North Vietnamese Communist captors.

He was edged out by George W. Bush for the Republican presidential nomination in 2000 but became his party’s White House candidate eight years later. After gambling on political neophyte Sarah Palin as his running mate, McCain lost to Obama, who became the first black U.S. president.

Obama said in a statement that he and McCain, despite their different backgrounds and political views, shared a belief in American ideals.

“We saw our political battles, even, as a privilege, something noble, an opportunity to serve as stewards of those high ideals at home, and to advance them around the world,” Obama wrote.

McCain, chairman of the Senate Armed Services Committee, was a frequent critic and target of his fellow Republican Trump, who was elected president in November 2016.

McCain denounced Trump for, among other things, his praise of Russian President Vladimir Putin and other leaders the senator described as foreign “tyrants.”

“Flattery secures his friendship, criticism his enmity,” McCain said of Trump in his memoir, “The Restless Wave,” which was released in May.

McCain castigated Trump in July for his summit with Putin, calling their joint news conference in Helsinki “one of the most disgraceful performances by an American president in memory.”

Defense Secretary James Mattis saluted McCain as a figure who “always put service to the nation before self.”

In Germany, whose government has clashed with Trump over a range of issues including trade and defense, Chancellor Angela Merkel said: “John McCain was guided by the firm conviction that the value of all political work could be found in serving freedom, democracy and the rule of law.”

French President Emmanuel Macron called McCain “a true American hero (whose) ... voice will be missed” and British Prime Minister Theresa May said he “embodied the idea of service over self.”

THUMBS-DOWN

McCain, a traditionally Republican foreign policy hawk, was admired in both parties for championing civility and compromise during an era of acrid partisanship in U.S. politics.

Slideshow ( 19 images )

But he also had a famous temper and rarely shied away from a fight, including several with Trump.

He was the central figure in one of the most dramatic congressional moments in Trump’s presidency when he returned to Washington shortly after his brain cancer diagnosis for a middle-of-the-night vote in July 2017.

Still bearing a black eye and scar from surgery, McCain gave a thumbs-down signal in a vote to scuttle a Trump-backed bill that would have repealed the Obamacare healthcare law and increased the number of Americans without health insurance by millions.

Trump was furious about McCain’s vote and frequently referred to it at rallies.

After Trump launched his presidential campaign in 2015, McCain condemned his hardline rhetoric on illegal immigration and said Trump had “fired up the crazies.” Trump retorted that McCain was “not a war hero,” adding: “I like people who weren’t captured.”

After Trump became president, McCain blasted what he called the president’s attempts to undermine the free press and rule of law and lamented the “half-baked, spurious nationalism” of the Trump era.

Slideshow ( 19 images )

MCCAIN VERSUS OBAMA

McCain, the son and grandson of U.S. Navy admirals, was elected to the U.S. House of Representatives in 1982 after more than two decades of Navy service.

Arizona next elected him to the U.S. Senate in 1986 to replace Barry Goldwater, the 1964 Republican presidential nominee revered by conservatives.

In running for president in 2008, McCain tried to succeed fellow Republican Bush at time when the United States was mired in wars in Afghanistan and Iraq, and stuck in a financial crisis.

It was a stark contrast between McCain, then a 72-year-old veteran of Washington, and the 47-year-old Obama, who was offering a “Yes, we can” message of change.

McCain tried to inject some youth into his campaign with his selection of Palin, Alaska’s governor, as his running mate. But her political inexperience and shaky interview performances raised concerns about her qualifications.

McCain voiced regret in his new memoir for not choosing then-Senator Joe Lieberman, a Democrat turned independent, as his running mate.

WAR INJURIES

McCain flew attack planes off aircraft carriers during the Vietnam War. In October 1967, his A-4 Skyhawk was shot down on a bombing mission over North Vietnam’s capital and he suffered two broken arms and a broken leg. A mob dragged him from a lake, broke his shoulder and stabbed him.

Held at the notorious “Hanoi Hilton” prison and other sites, McCain was beaten and tortured, suffering broken bones and dysentery. He was released on March 14, 1973, but left with permanent infirmities.

Several U.S. citizens living in Vietnam adorned a monument erected at the site of the plane crash with flowers on Sunday in tribute.

“Not only did Senator McCain actively contribute to Vietnam-U.S. ties, he was a friend of Vietnam who won huge love from Vietnamese people at many levels,” Vietnam’s ambassador to the United States, Ha Kim Ngoc, told the state-run Voice of Vietnam radio service.

In Congress, McCain prided himself on his history of working across party lines on immigration, climate change and campaign finance reform.

He supported Bush’s 2003 invasion of Iraq but also spoke out against the Bush administration’s use of waterboarding, a type of simulated drowning widely considered torture, and other extreme interrogation tactics in the aftermath of the Sept. 11, 2001, attacks.

McCain was born on Aug. 29, 1936, at an American naval installation in the Panama Canal Zone - U.S. territory at the time - where his father was stationed.

McCain divorced his wife Carol after 15 years of marriage in 1980 and weeks later married the then Cindy Henley, daughter of a wealthy beer distributor in Arizona.

A dark period for McCain came as one of the “Keating Five” group of senators accused of improperly intervening with federal regulators to help political contributor and bank executive Charles Keating, whose Lincoln Savings and Loan failed in 1989, costing taxpayers $3.4 billion.

McCain was cleared of wrongdoing in 1991 but the Senate Ethics Committee rebuked him for poor judgment.

On July 25, 2017, McCain delivered a Senate floor speech not long after his cancer diagnosis that was widely seen as his farewell address. It called on fellow Republicans to stand up to Trump and for all lawmakers to work together to keep America as a “beacon of liberty” in the world.