WASHINGTON (AP) — Sen. John McCain, who faced down his captors in a Vietnam prisoner of war camp with jut-jawed defiance and later turned his rebellious streak into a 35-year political career that took him to Congress and the Republican presidential nomination, died Saturday after battling brain cancer for more than a year. He was 81.

McCain, with his irascible grin and fighter-pilot moxie, was a fearless and outspoken voice on policy and politics to the end, unswerving in his defense of democratic values and unflinching in his criticism of his fellow Republican, President Donald Trump. He was elected to the Senate from Arizona six times but twice thwarted in seeking the presidency.

An upstart presidential bid in 2000 didn't last long. Eight years later, he fought back from the brink of defeat to win the GOP nomination, only to be overpowered by Democrat Barack Obama. McCain chose a little-known Alaska governor as his running mate in that race, and turned Sarah Palin into a national political figure.

After losing to Obama in an electoral landslide, McCain returned to the Senate determined not to be defined by a failed presidential campaign in which his reputation as a maverick had faded. In the politics of the moment and in national political debate over the decades, McCain energetically advanced his ideas and punched back hard at critics — Trump not least among them.

The scion of a decorated military family, McCain embraced his role as chairman of the Armed Services Committee, pushing for aggressive U.S. military intervention overseas and eager to contribute to "defeating the forces of radical Islam that want to destroy America."

Asked how he wanted to be remembered, McCain said simply: "That I made a major contribution to the defense of the nation."

One dramatic vote he cast in the twilight of his career in 2017 will not soon be forgotten, either: As the decisive "no" on Senate GOP legislation to repeal the Affordable Care Act, McCain became the unlikely savior of Obama's trademark legislative achievement.

Taking a long look back in his valedictory memoir, "The Restless Wave," McCain wrote of the world he inhabited: "I hate to leave it. But I don't have a complaint. Not one. 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."

Throughout his long tenure in Congress, McCain played his role with trademark verve, at one hearing dismissing a protester by calling out, "Get out of here, you low-life scum."

But it was just as notable when he held his sharp tongue, in service of a party or political gain.

Most remarkably, he stuck by Trump as the party's 2016 presidential nominee even when Trump questioned his status as a war hero by saying: "I like people who weren't captured." McCain declared the comment offensive to veterans, but urged the men "put it behind us and move forward."

His breaking point with Trump was the release a month before the election of a lewd audio in which Trump said he could kiss and grab women. McCain withdrew his support and said he'd write in "some good conservative Republican who's qualified to be president."

By the time McCain cast his vote against the GOP health bill, six months into Trump's presidency, the two men were openly at odds. Trump railed against McCain publicly over the vote, and McCain remarked that he no longer listened to what Trump had to say because "there's no point in it."

By then, McCain had disclosed his brain cancer diagnosis and returned to Arizona to seek treatment. His vote to kill the GOP's years-long Obamacare repeal drive — an issue McCain himself had campaigned on — came not long after the diagnosis, a surprising capstone to his legislative career.

In his final months, McCain did not go quietly, frequently jabbing at Trump and his policies from the remove of his Hidden Valley family retreat in Arizona. He opposed the president's nominee for CIA director because of her past role in overseeing torture, scolded Trump for alienating U.S. allies at an international summit, labeled the administration's zero-tolerance immigration policy "an affront to the decency of the American people" and denounced the Trump-Putin summit in Helsinki as a "tragic mistake" in which the president put on "one of the most disgraceful performances by an American president in memory."

On Aug. 13, Trump signed into law a $716 billion defense policy bill named in honor of the senator. Trump signed the John S. McCain National Defense Authorization Act in a ceremony at a military base in New York — without one mention of McCain.

John Sidney McCain III was born in 1936 in the Panana Canal zone, where his father was stationed in the military.

He followed his father and grandfather, the Navy's first father-and-son set of four-star admirals, to the Naval Academy, where he enrolled in what he described a "four-year course of insubordination and rebellion." His family yawned at the performance. A predilection for what McCain described as "quick tempers, adventurous spirits, and love for the country's uniform" was encoded in his family DNA.

On October 1967, McCain was on his 23rd bombing round over North Vietnam when he was shot out of the sky and taken prisoner.

Year upon year of solitary confinement, deprivation, beatings and other acts of torture left McCain so despairing that at one point he weakly attempted suicide. But he also later wrote that his captors had spared him the worst of the abuse inflicted on POWs because his father was a famous admiral. "I knew that my father's identity was directly related to my survival," he wrote in one of his books.

When McCain's Vietnamese captors offered him early release as a propaganda ploy, McCain refused to play along, insisting that those captured first should be the first set free.

In his darkest hour in Vietnam, McCain's will had been broken and he signed a confession that said, "I am a black criminal and I have performed deeds of an air pirate."

Even then, though, McCain refused to make an audio recording of his confession and used stilted written language to signal he had signed it under duress. And, to the end of his captivity, he continued to exasperate his captors with his defiance.

Throughout, McCain played to the bleachers, shouting obscenities at guards to bolster the spirits of fellow captives. Appointed by the POWs to act as camp entertainment officer, chaplain and communications chief, McCain imparted comic relief, literary tutorials, news of the day, even religious sustenance.

Bud Day, a former cellmate and Medal of Honor winner, said McCain's POW experience "took some great iron and turned him into steel."

McCain returned home from his years as a POW on crutches and never regained full mobility in his arms and leg.

He once said he'd "never known a prisoner of war who felt he could fully explain the experience to anyone who had not shared it." Still he described the time as formative and "a bit of a turning point in me appreciating the value of serving a cause greater than your self-interest."

But it did not tame his wild side, and his first marriage, to Carol Shepp, was a casualty of what he called "my greatest moral failing." The marriage to Shepp, who had been in a crippling car accident while McCain was imprisoned, ended amiably. McCain admitted the breakup was caused by "my own selfishness and immaturity."

One month after his divorce, McCain in 1981 married Cindy Hensley, the daughter of a wealthy beer distributor in Arizona.

In one day, McCain signed his Navy discharge papers and flew west with his new wife to a new life. By 1982, he'd been elected to the House and four years later to an open Senate seat. He and Cindy had four children, to add to three from his first marriage. Their youngest was adopted from Bangladesh.

McCain cultivated a conservative voting record and a reputation as a tightwad with taxpayer dollars. But just months into his Senate career, he made what he called "the worst mistake" of his life. He participated in two meetings with bank regulators on behalf of Charles Keating, a friend, campaign contributor and savings and loan financier later convicted of securities fraud.

As the industry collapsed, McCain was tagged as one of the Keating Five — senators who, to varying degrees, were accused of trying to get regulators to ease up on Keating. McCain was cited by the Senate Ethics Committee for "poor judgment."

To have his honor questioned, he said, was in some ways worse than the torture he endured in Vietnam.

In the 1990s, McCain shouldered another wrenching issue, the long effort to account for American soldiers still missing from the war and to normalize relations with Vietnam.

"People don't remember how ugly the POW-MIA issue was," former Democratic Sen. Bob Kerrey, a fellow Vietnam veteran, later recalled in crediting McCain for standing up to significant opposition. "I heard people scream in his face, holding him responsible for the deaths of POWs."

Over three decades in the Senate, McCain became a standard-bearer for reforming campaign donations. He denounced pork-barrel spending for legislators' pet projects and cultivated a reputation as a deficit hawk and an independent voice. His experience as a POW made him a leading voice against the use of torture. He achieved his biggest legislative successes when making alliances with Democrats.

But faced with a tough GOP challenge for his Senate seat in 2010, McCain disowned chapters in his past and turned to the right on a number of hot-button issues, including gays in the military and climate change. And when the Supreme Court in 2010 overturned the campaign finance restrictions that he'd work so hard to enact, McCain seemed resigned.

"It is what it is," he said.

After surviving that election, though, McCain took on conservatives in his party over the federal debt and Democrats over foreign policy. McCain never softened on his opposition to the U.S. use of torture, even in the recalibrations of the post-9/11 world. When the Senate in 2014 released a report on the CIA's harsh interrogation techniques at secret overseas facilities after the 9/11 attacks, McCain said the issue wasn't "about our enemies. It's about us. It's about who we were, who we are and who we aspire to be. It's about how we represent ourselves to the world."

During his final years in the Senate, McCain was perhaps the loudest advocate for U.S. military involvement overseas - in Iraq, Syria, Libya and more. That often made him a critic of first Obama and then Trump, and placed him further out of step with the growing isolationism within the GOP.

In October 2017, McCain unleashed some his most blistering criticism of Trump's "America first" foreign policy approach — without mentioning the president by name — in describing a "half-baked, spurious nationalism cooked up by people who would rather find scapegoats than solve problems."

Few politicians matched McCain's success as an author. His 1999 release "Faith Of My Fathers" was a million seller that was highly praised and helped launch his run for president in 2000. His most recent bestseller and planned farewell, "The Restless Wave," came out in May 2018.

___

Follow Nancy Benac on Twitter at http://twitter.com/nbenac

Copyright 2018 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.