Vietnam veteran and Republican presidential candidate in 2008, McCain had been battling glioblastoma, an aggressive form of brain cancer discovered in July 2017.
John McCain, the former prisoner of war in Vietnam who ran unsuccessfully for US president as a self-styled maverick Republican in 2008 and became a prominent critic of President Donald Trump, died on Saturday, his office said. He was 81.
McCain, a US senator from Arizona for over three decades, had been battling glioblastoma, an aggressive brain cancer, discovered by his doctors in July 2017, and had not been at the US Capitol in 2018. He also had surgery for an intestinal infection in April.
A statement from his office said: "Senator John Sidney McCain III died at 4:28 pm on August 25, 2018. With the senator when he passed were his wife Cindy and their family. At his death, he had served the United States of America faithfully for sixty years."
No further details were immediately provided.
My heart is broken. I am so lucky to have lived the adventure of loving this incredible man for 38 years. He passed the way he lived, on his own terms, surrounded by the people he loved, in the the place he loved best.— Cindy McCain (@cindymccain) August 26, 2018
"My heart is broken. I am so lucky to have lived the adventure of loving this incredible man for 38 years," Cindy McCain wrote on Twitter. "He passed the way he lived, on his own terms, surrounded by the people he loved, in the place he loved best."
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 during 5-1/2 years as a prisoner.
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 vice presidential running mate, McCain lost in 2008 to Democrat Barack Obama, who became the first black U.S. president.
McCain, the chairman of the Senate Armed Services Committee, was a frequent critic as well as a 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 in July had castigated Trump for his summit with Putin, issuing a statement that called their joint news conference in Helsinki "one of the most disgraceful performances by an American president in memory." He said Trump was "not only unable but unwilling to stand up to Putin."
Sources close to McCain have said Trump would not be invited to the funeral.
McCain, a foreign policy hawk with a traditional Republican view of world affairs, was admired in both parties for championing civility and compromise during an era of acrid partisanship in US politics. But he also had a famous temper and rarely shied away from a fight. He had several with Trump.
He was the central figure in one of the most dramatic moments in Congress of Trump's presidency when he returned to Washington shortly after his brain cancer diagnosis for a middle-of-the-night Senate 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 but without mentioning McCain by name.
After Trump in 2015 launched his presidential campaign, McCain condemned his hard-line 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.
McCain denounced Trump's performance at a summit meeting with Putin in July as "a tragic mistake," adding, "The damage inflicted by President Trump’s naivete, egotism, false equivalence, and sympathy for autocrats is difficult to calculate."
McCain, the son and grandson of US Navy admirals, was elected to the US House of Representatives from Arizona in 1982 after more than two decades of Navy service.
He served four years in the House before Arizona voters elected him to the 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 an unpopular fellow Republican in Bush, who was leaving office with the country 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 the Washington establishment, and the 47-year-old Obama, who was offering a "Yes, we can" message of change.
McCain tried to inject some youth and enthusiasm into his campaign with his selection of Palin, Alaska's governor, as his running mate. But the choice backfired as her political inexperience and shaky performances in media interviews raised concerns about her qualifications.
In his new book, McCain voiced regret for not choosing then-Senator Joe Lieberman, a Democrat turned independent, as his running mate.
McCain wrote that he had originally settled on Lieberman, Democrat Al Gore's running mate in the 2000 election, but was warned by Republican leaders that Lieberman's views on social issues, including support for abortion rights, would "fatally divide" the party.
"It was sound advice that I could reason for myself," McCain wrote. "But my gut told me to ignore it and I wish I had."
Obama won 53 percent of the vote to McCain's 45.6 percent.
During the Vietnam War, McCain flew attack planes off aircraft carriers. He was preparing for a bombing run in 1967 when a missile inadvertently fired from another plane hit his fuel tanks, triggering a fatal explosion and fire. He suffered shrapnel wounds.
A few months later on October 26, 1967, McCain's 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 in the crash. A mob then 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 was left with permanent infirmities.
In Congress, McCain built a generally conservative record, opposing abortion and advocating higher defence spending. He supported Bush's 2003 invasion of Iraq and criticised Obama for not doing more to intervene in Syria's civil war.
Still, he prided himself on his reputation as a maverick and had a history of working across party lines on immigration, climate change and campaign finance reform.
He also spoke out against the Bush administration's use of waterboarding, a torture technique that simulates drowning, and other harsh interrogation tactics on detainees in the aftermath of the September 11, 2001, attacks.
He urged the closure of the prison for foreign terrorism suspects at the US naval base at Guantanamo Bay, Cuba, and also sponsored an anti-torture measure that passed Congress in 2005.
In a 2002 memoir, McCain wrote, "I'm an independent-minded, well-informed public servant to some. And to others, I'm a self-styled, self-righteous maverick pain in the ass."
John Sidney McCain III was born on August 29, 1936, at an American naval installation in the Panama Canal Zone — US territory at the time when his father was stationed there.
He conceded he was a "smart ass" during his years at the U.S. Naval Academy and graduated fifth from the bottom of his class.
McCain divorced his wife Carol after 15 years of marriage in 1980 and weeks later married the former 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 at a cost to taxpayers of $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 included a call to 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.
"That is the cause that binds us and is so much more powerful and worthy than the small differences that divide us," McCain said.
While he had many disagreements with fellow politicians, the Republican stalwart's integrity was not at question, and condolences came swift from the highest reaches of American politics after his passing.
Ex-president Barack Obama, the Democrat to whom McCain lost the presidency in the 2008 elections, said, "We are all in his debt."
"John McCain and I were members of different generations, came from completely different backgrounds and competed at the highest level of politics," Obama said in a statement.
"But we shared, for all our differences, a fidelity to something higher the ideals for which generations of Americans and immigrants alike have fought, marched and sacrificed."
Our statement on the passing of Senator John McCain: pic.twitter.com/3GBjNYxoj5— Barack Obama (@BarackObama) August 26, 2018
Former vice president Al Gore — who served under Democrat Bill Clinton — said: "I always admired and respected John from the opposite side of the aisle, because he thrived under pressure, and would work to find common ground, no matter how hard."
President Donald Trump, who once mocked McCain's war record, said he sent his "deepest sympathies and respect."