A look at the formative times and turmoil that shaped a historic American figure, with Carl Hulse, The Times’s chief Washington correspondent.

A look at the formative times and turmoil that shaped a historic American figure, with Carl Hulse, The Times’s chief Washington correspondent. Credit... Image by Stephen Crowley/The New York Times

John S. McCain, the proud naval aviator who climbed from depths of despair as a prisoner of war in Vietnam to pinnacles of power as a Republican congressman and senator from Arizona and a two-time contender for the presidency, died on Saturday at his home in Arizona. He was 81.

According to a statement from his office, Mr. McCain died at 4:28 p.m. local time. He had suffered from a malignant brain tumor, called a glioblastoma, for which he had been treated periodically with radiation and chemotherapy since its discovery in 2017.

Despite his grave condition, he soon made a dramatic appearance in the Senate to cast a thumbs-down vote against his party’s drive to repeal the Affordable Care Act. But while he was unable to be in the Senate for a vote on the Republican tax bill in December, his endorsement was crucial, though not decisive, in the Trump administration’s lone legislative triumph of the year.

ADVERTISEMENT

A son and grandson of four-star admirals who were his larger-than-life heroes, Mr. McCain carried his renowned name into battle and into political fights for more than a half-century. It was an odyssey driven by raw ambition, the conservative instincts of a shrewd military man, a rebelliousness evident since childhood and a temper that sometimes bordered on explosiveness.

Image Mr. McCain, bottom right, in 1965 with his Navy squadron. While in the Navy, he was cocky and combative and resisted discipline. Credit... National Archives

Nowhere were those traits more manifest than in Vietnam, where he was stripped of all but his character. He boiled over in foul curses at his captors. Because his father was the commander of all American forces in the Pacific during most of his five and a half years of captivity, Mr. McCain, a Navy lieutenant commander, became the most famous prisoner of the war, a victim of horrendous torture and a tool of enemy propagandists.

Shot down over Hanoi, suffering broken arms and a shattered leg, he was subjected to solitary confinement for two years and beaten frequently. Often he was suspended by ropes lashing his arms behind him. He attempted suicide twice. His weight fell to 105 pounds. He rejected early release to keep his honor and to avoid an enemy propaganda coup or risk demoralizing his fellow prisoners.

He finally cracked under torture and signed a “confession.” No one believed it, although he felt the burden of betraying his country. To millions of Americans, Mr. McCain was the embodiment of courage: a war hero who came home on crutches, psychologically scarred and broken in body, but not in spirit. He underwent long medical treatments and rehabilitation, but was left permanently disabled, unable to raise his arms over his head. Someone had to comb his hair.

ADVERTISEMENT

His mother, Roberta McCain, Navy all the way, inspired his political career. After retiring from the Navy and settling in Arizona, he won two terms in the House of Representatives, from 1983 to 1987, and six in the Senate. He was a Reagan Republican to start with, but later moved right or left, a maverick who defied his party’s leaders and compromised with Democrats.

He lost the 2000 Republican presidential nomination to George W. Bush, who won the White House.

In 2008, against the backdrop of a growing financial crisis, Mr. McCain made the most daring move of his political career, seeking the presidency against the first major-party African-American nominee, Barack Obama. With national name recognition, a record for campaign finance reform and a reputation for candor — his campaign bus was called the Straight Talk Express — Mr. McCain won a series of primary elections and captured the Republican nomination.

Slide 1 of 12. In 2008, against the backdrop of a growing financial crisis, John McCain sought the presidency against Barack Obama, the first African-American nominee from a major party. Mr. McCain selected Gov. Sarah Palin of Alaska as his running mate. Credit... Damon Winter/The New York Times Slide 2 of 12. The Republican National Convention in St. Paul, where Mr. McCain captured the party’s nomination in the 2008 presidential race. Eight years earlier, he had lost the Republican nomination to George W. Bush. Credit... Damon Winter/The New York Times Slide 3 of 12. Mr. McCain’s wife, Cindy, and his daughter Meghan McCain, right, at the Republican National Convention in 2008. From left, Ms. Palin’s husband, Todd; their daughters Piper, Willow and Bristol; and their infant son Trig. Credit... Jim Wilson/The New York Times Slide 4 of 12. His campaign bus during the Republican presidential primary in 2008 was called the Straight Talk Express, to reflect his reputation for candor. Credit... Todd Heisler/The New York Times Slide 5 of 12. A rally in Blaine, Minn., in 2008, when he was campaigning against Mr. Obama. Credit... Todd Heisler/The New York Times Slide 6 of 12. Mr. and Ms. McCain at a store selling Ohio State University memorabilia in Columbus, Ohio, in 2008. Credit... Jim Wilson/The New York Times Slide 7 of 12. Ms. Palin’s plane waited for her arrival at the airport in Anchorage on Election Day in 2008. Credit... Todd Heisler/The New York Times Slide 8 of 12. Ms. Palin at a rally in Media, Penn., in September 2008. Mr. McCain’s choice of running mate was meant to be a bold and unconventional move, but it proved a handicap. Voters worried about her qualifications. Credit... Todd Heisler/The New York Times Slide 9 of 12. Eight Republican presidential candidates, including Mr. McCain, preparing for a debate in Johnston, Iowa, in December 2007. Credit... Joshua Lott for The New York Times Slide 10 of 12. Mr. Obama and Mr. McCain at the third and final presidential debate at Hofstra University in October 2008. Though Mr. McCain was an outspoken critic of the Obama administration, he became a pivotal figure in the Senate during the Obama presidency. Credit... Damon Winter/The New York Times Slide 11 of 12. Mr. McCain, Ms. McCain, Mr. Obama and Mayor Michael R. Bloomberg of New York visited the site of the World Trade Center on Sept. 11, 2008. Credit... Stephen Crowley/The New York Times Slide 12 of 12. Mr. McCain waiting for a live television interview in 2007. On Election Day, Mr. Obama won the presidency with 365 Electoral College votes to Mr. McCain’s 173. Credit... Stephen Crowley/The New York Times 1 / 12 In 2008, against the backdrop of a growing financial crisis, John McCain sought the presidency against Barack Obama, the first African-American nominee from a major party. Mr. McCain selected Gov. Sarah Palin of Alaska as his running mate. Credit... Damon Winter/The New York Times

The Republican National Convention in St. Paul, where Mr. McCain captured the party’s nomination in the 2008 presidential race. Eight years earlier, he had lost the Republican nomination to George W. Bush. Credit... Damon Winter/The New York Times

Mr. McCain’s wife, Cindy, and his daughter Meghan McCain, right, at the Republican National Convention in 2008. From left, Ms. Palin’s husband, Todd; their daughters Piper, Willow and Bristol; and their infant son Trig. Credit... Jim Wilson/The New York Times

His campaign bus during the Republican presidential primary in 2008 was called the Straight Talk Express, to reflect his reputation for candor. Credit... Todd Heisler/The New York Times

A rally in Blaine, Minn., in 2008, when he was campaigning against Mr. Obama. Credit... Todd Heisler/The New York Times

Mr. and Ms. McCain at a store selling Ohio State University memorabilia in Columbus, Ohio, in 2008. Credit... Jim Wilson/The New York Times

Ms. Palin’s plane waited for her arrival at the airport in Anchorage on Election Day in 2008. Credit... Todd Heisler/The New York Times

Ms. Palin at a rally in Media, Penn., in September 2008. Mr. McCain’s choice of running mate was meant to be a bold and unconventional move, but it proved a handicap. Voters worried about her qualifications. Credit... Todd Heisler/The New York Times

Eight Republican presidential candidates, including Mr. McCain, preparing for a debate in Johnston, Iowa, in December 2007. Credit... Joshua Lott for The New York Times

Mr. Obama and Mr. McCain at the third and final presidential debate at Hofstra University in October 2008. Though Mr. McCain was an outspoken critic of the Obama administration, he became a pivotal figure in the Senate during the Obama presidency. Credit... Damon Winter/The New York Times

Mr. McCain, Ms. McCain, Mr. Obama and Mayor Michael R. Bloomberg of New York visited the site of the World Trade Center on Sept. 11, 2008. Credit... Stephen Crowley/The New York Times

Mr. McCain waiting for a live television interview in 2007. On Election Day, Mr. Obama won the presidency with 365 Electoral College votes to Mr. McCain’s 173. Credit... Stephen Crowley/The New York Times In 2008, against the backdrop of a growing financial crisis, John McCain sought the presidency against Barack Obama, the first African-American nominee from a major party. Mr. McCain selected Gov. Sarah Palin of Alaska as his running mate. Credit... Damon Winter/The New York Times

The Republican National Convention in St. Paul, where Mr. McCain captured the party’s nomination in the 2008 presidential race. Eight years earlier, he had lost the Republican nomination to George W. Bush. Credit... Damon Winter/The New York Times

Mr. McCain’s wife, Cindy, and his daughter Meghan McCain, right, at the Republican National Convention in 2008. From left, Ms. Palin’s husband, Todd; their daughters Piper, Willow and Bristol; and their infant son Trig. Credit... Jim Wilson/The New York Times

His campaign bus during the Republican presidential primary in 2008 was called the Straight Talk Express, to reflect his reputation for candor. Credit... Todd Heisler/The New York Times

A rally in Blaine, Minn., in 2008, when he was campaigning against Mr. Obama. Credit... Todd Heisler/The New York Times

Mr. and Ms. McCain at a store selling Ohio State University memorabilia in Columbus, Ohio, in 2008. Credit... Jim Wilson/The New York Times

Ms. Palin’s plane waited for her arrival at the airport in Anchorage on Election Day in 2008. Credit... Todd Heisler/The New York Times

Ms. Palin at a rally in Media, Penn., in September 2008. Mr. McCain’s choice of running mate was meant to be a bold and unconventional move, but it proved a handicap. Voters worried about her qualifications. Credit... Todd Heisler/The New York Times

Eight Republican presidential candidates, including Mr. McCain, preparing for a debate in Johnston, Iowa, in December 2007. Credit... Joshua Lott for The New York Times

Mr. Obama and Mr. McCain at the third and final presidential debate at Hofstra University in October 2008. Though Mr. McCain was an outspoken critic of the Obama administration, he became a pivotal figure in the Senate during the Obama presidency. Credit... Damon Winter/The New York Times

Mr. McCain, Ms. McCain, Mr. Obama and Mayor Michael R. Bloomberg of New York visited the site of the World Trade Center on Sept. 11, 2008. Credit... Stephen Crowley/The New York Times

Mr. McCain waiting for a live television interview in 2007. On Election Day, Mr. Obama won the presidency with 365 Electoral College votes to Mr. McCain’s 173. Credit... Stephen Crowley/The New York Times

ADVERTISEMENT

But his selection of Gov. Sarah Palin of Alaska as his running mate, although meant to be seen as a bold, unconventional move in keeping with his maverick’s reputation, proved a severe handicap. She was the second female major-party nominee for vice president (and the first Republican), but voters worried about her qualifications to serve as president, and about Mr. McCain’s age — he would be 72, the oldest person ever to take the White House. In a 2018 memoir, “The Restless Wave: Good Times, Just Causes, Great Fights and Other Appreciations,” he defended Ms. Palin’s campaign performance, but expressed regret that he had not instead chosen Senator Joseph I. Lieberman, a Democrat-turned-independent.

At some McCain rallies, vitriolic crowds disparaged black people and Muslims, and when a woman said she did not trust Mr. Obama because “he’s an Arab,” Mr. McCain, in one of the most lauded moments of his campaign, replied: “No, ma’am. He’s a decent family man, a citizen that I just happen to have disagreements with on fundamental issues.”

Analysts later said that Mr. Obama had engineered a nearly perfect campaign. And Mr. McCain confronted a hostile political environment for Republicans, who were dragged down by President George W. Bush’s dismal approval ratings amid the economic crisis and an unpopular war in Iraq.

On Election Day, Mr. McCain lost most of the battleground states and some that were traditionally Republican. Mr. Obama won with 53 percent of the popular vote to Mr. McCain’s 46 percent, and 365 Electoral College votes to Mr. McCain’s 173.

ADVERTISEMENT

“Few of us have been tested the way John once was, or required to show the kind of courage that he did,” Mr. Obama said Saturday. “But all of us can aspire to the courage to put the greater good above our own. At John’s best, he showed us what that means.”

In the Gang of Eight

Image Mr. McCain in 2013 with a bipartisan group of senators, known as the Gang of Eight, that sought compromises on comprehensive immigration reform. Credit... Doug Mills/The New York Times

Returning to his Senate duties, the resilient Mr. McCain moved to the right politically to fend off a Tea Party challenge to his 2010 re-election. He voted against the Affordable Care Act, Mr. Obama’s signature health care plan, which became law in 2010. He endorsed Mitt Romney’s losing Republican bid for the presidency in 2012.

But while he was a persistent and outspoken critic of the Obama administration, Mr. McCain had by 2013 become a pivotal figure in the Senate, meeting with Mr. Obama and occasionally fashioning deals with him. He joined a bipartisan group of senators, known as the Gang of Eight, that sought compromises on comprehensive immigration reform.

ADVERTISEMENT

“When Mr. McCain is with the president — on immigration and in brokering the recent deal to secure Senate approval of stalled Obama nominees — they can usually trump the political right,” The New York Times said in a 2013 news analysis. “When he is against him — sabotaging Mr. Obama’s plan last year to nominate Susan E. Rice as secretary of state — the White House rarely prevails.”

As Congress reconvened in January 2015 with Republicans in control of the Senate, Mr. McCain achieved his longtime goal to become chairman of the Armed Services Committee, with the power to advance his national security and fiscal objectives under a $600 billion military policy bill. He considered the post second only to occupying the White House as commander in chief.

Image Mr. McCain in 2016 before a Senate Armed Services Committee hearing. He served six terms in the Senate. Credit... Drew Angerer for The New York Times

With the rise of Donald J. Trump, the Republican flame thrower who steered American politics sharply to the right after his election in 2016 as the nation’s 45th president, Mr. McCain was one of the few powerful Republican voices in Congress to push back against Mr. Trump’s often harsh, provocative statements and Twitter posts and his tide of changes.

ADVERTISEMENT

In his end-of-life memoir, Mr. McCain scorned Mr. Trump’s seeming admiration for autocrats and disdain for refugees. “He seems uninterested in the moral character of world leaders and their regimes,” he wrote of the president. “The appearance of toughness or a reality show facsimile of toughness seems to matter more than any of our values. Flattery secures his friendship, criticism his enmity.”

Long before Mr. Trump was criticized as setting new lows for public discourse, Mr. McCain himself had used coarse language and blunt insults, although they were far less assertive, and he often used them in jest. He called Secretary of State John Kerry, a Democrat, “a human wrecking ball,” and the right-wing Republican Senators Ted Cruz of Texas and Rand Paul of Kentucky “wacko birds.”

Personal animus between Mr. McCain and Mr. Trump arose in the Republican presidential primaries in 2016. After months of boasts by Trump about his wealth, celebrity and deal-making as qualifications for the White House, and his dismissive capsule characterizations of climate change as “a hoax” and the Iraq war as “a mistake,” Mr. McCain and Mr. Romney, with standing as the previous two Republican presidential nominees, denounced Mr. Trump as unfit for the presidency.

Saying Mr. Trump had neither the temperament nor the judgment for the White House, Mr. McCain and Mr. Romney called him ignorant on foreign policy and said he had made “dangerous” statements on national security. They warned that his election might imperil the United States and its democratic systems.

ADVERTISEMENT

In a venomous response, Mr. Trump denigrated Mr. Romney as a “failed candidate” and “a loser” beaten by Mr. Obama. He had little to say about Mr. McCain. But months earlier, Mr. Trump, who had never served in the military (or held public office) had derided Mr. McCain as a bogus war hero and made light of his years of captivity and torture.

Image Mr. McCain campaigning with Mitt Romney in 2012 in Pensacola, Fla. He endorsed Mr. Romney’s Republican bid for the presidency that year. Credit... Emmanuel Dunand/Agence France-Presse — Getty Images

“He’s a war hero because he was captured,” Mr. Trump said. “I like people who weren’t captured.”

Mr. McCain held his fire. But the nation was shocked. An avalanche of denunciations tumbled from editorial boards and political leaders, but the outrage faded into the tapestry of Mr. Trump’s provocations against Mexicans, Muslims, women and black and Hispanic people. Trump supporters, who were mostly white, said his biases showed a refreshing willingness to disregard political correctness.

On Saturday night, Mr. Trump expressed his sympathies and respect for Mr. McCain’s family, but refrained from commenting on the senator himself.

ADVERTISEMENT

A No-Show in Cleveland

As the Trump juggernaut rolled on, Mr. McCain, campaigning for re-election to his sixth six-year term, did not attend the Republican National Convention in Cleveland, but said he would support his party’s nominee. (Mr. McCain withdrew that support months later after a recording surfaced exposing lewd comments about women by Mr. Trump, who bragged that his celebrity allowed him to grope them.)

Days after the Democrats nominated Hillary Clinton as the first major-party female candidate for the presidency, Mr. McCain rebuked Mr. Trump for his comments about the family of a Muslim Army captain killed by a suicide bomber as he tried to save fellow American troops in Iraq in 2004. Given the podium at the Democratic convention, Khizr Khan, the father of the captain, Humayun Khan, had denounced Mr. Trump for suggesting that Muslims harbored terrorist sympathies.

With his wife, Ghazala, at his side, the father held up a pocket-size copy of the Constitution and asked if Mr. Trump had read it.

In response, Mr. Trump belittled the parents, saying the soldier’s father had delivered the speech because his wife had not been “allowed” to speak. His implication, that Mrs. Khan had not spoken because of female subservience in some strains of Islam, drew widespread condemnation, led on Capitol Hill by Senator McCain.

ADVERTISEMENT

“While our party has bestowed upon him the nomination, it is not accompanied by unfettered license to defame those who are the best among us,” Mr. McCain said. “I challenge the nominee to set the example for what our country can and should represent.”

Soon after Mr. McCain’s statement, other Republican senators offered their own condemnations. In ensuing days, as outrage over the Trump remarks spread, Mr. Trump told his Twitter followers that Mr. Khan had “no right” to “viciously” attack him.

Seemingly impervious to criticism of any kind, Mr. Trump, who had easily won nomination, turned his guns on Mrs. Clinton. After a bruising campaign laden with Trump falsehoods and scurrilous innuendo, he defeated her in the general election, losing the popular vote by nearly three million but winning in the Electoral College.

After the election, Mr. McCain, determined to let the new administration take shape, said he would temporarily not discuss Mr. Trump publicly.

ADVERTISEMENT

But weeks after President Trump moved into the White House and began blindsiding the public and sometimes the government with executive orders and mixed messages on immigration, foreign policy and other issues, Mr. McCain, himself newly re-elected, let loose.

At a security conference in Munich, he delivered a forceful critique of Mr. Trump’s “America First” program before a receptive audience of allied officials and foreign policy experts dismayed at the administration’s drift from seven decades of Western alliances.

“Make no mistake, my friends, these are dangerous times,” Mr. McCain said. “But you should not count America out, and we should not count each other out.”

As for Mr. Trump’s claim that his White House was operating like a “fine-tuned machine,” Mr. McCain said, “In many respects, this administration is in disarray.”

ADVERTISEMENT

Appearing on the NBC News program “Meet the Press” a day later, Mr. McCain punctured Mr. Trump’s contention that the news media was “the enemy of the American people.”

“The first thing that dictators do is shut down the press,” Mr. McCain, a strong defender of the First Amendment, told his national television audience. While not expressly calling the president a dictator, he said, “We need to learn the lessons of history.”

[John McCain to lie in state at capitols in Washington and Arizona. Here’s what that means.]

For a senator who had long backed free trade, NATO and assertive foreign policies, and who had harbored suspicions about Russian intentions, Mr. McCain’s differences with Mr. Trump ran deep. He denounced Russia for “interfering” in the presidential election and called for a select Senate committee to investigate the Kremlin’s cyberactivities.

His disapproval of Mr. Trump perhaps peaked in July, after the president and President Vladimir V. Putin of Russia met privately in Helsinki, Finland, and then participated in an extraordinary joint news conference there. Responding to Mr. Trump’s performance, in which the president spoke favorably of his Russian counterpart and questioned American intelligence findings that the Russians had interfered in the 2016 presidential election, Mr. McCain declared, “No prior president has ever abased himself more abjectly before a tyrant.”

ADVERTISEMENT

Weeks later, in signing a $716 billion military spending bill named in Mr. McCain’s honor, Mr. Trump did not mention the senator by name in what was widely interpreted as a deliberate snub.

Although Mr. McCain was sharply critical of Mr. Trump, especially when he thought the new president had threatened to overstep domestic or national interests, he remained broadly supportive of the administration’s agenda.

After an acrimonious yearlong fight over replacing the late Justice Antonin Scalia on the Supreme Court, Mr. McCain joined the Senate’s 54-to-45 majority to confirm Mr. Trump’s selection of Neil Gorsuch as an associate justice. Justice Gorsuch’s installation tipped the court’s balance in favor of a conservative majority that seemed destined to last for years.

Mr. McCain voted for all but two of Mr. Trump’s 15 cabinet selections and eight other administration posts requiring Senate confirmation. But he also chastised Mr. Trump for comments equating Russian and American interests. “That moral equivalency is a contradiction of everything the United States has ever stood for in the 20th and 21st centuries,” he said.

ADVERTISEMENT

During a Senate Intelligence Committee hearing taking testimony from James B. Comey, the former F.B.I. director who was fired by Mr. Trump, Mr. McCain posed confusing questions, seeming to conflate the 2016 investigation of Mrs. Clinton’s use of a private email server as secretary of state with the 2017 investigation of Russian interference in the American election. He later issued a clarification.

“What I was trying to get at was whether Mr. Comey believes that any of his interactions with the president rise to the level of obstruction of justice,” he said. “In the case of Secretary Clinton’s emails, Mr. Comey was willing to step beyond his role as an investigator and state his belief about what ‘no reasonable prosecutor’ would conclude about the evidence. I wanted Mr. Comey to apply the same approach to the key question surrounding his interactions with President Trump — whether or not the president’s conduct constitutes obstruction of justice.”

Image Days after surgery for brain cancer, in July 2017, Mr. McCain returned to the Senate to take part in the vote to repeal and replace the Affordable Care Act. In a dramatic televised moment, he voted not to replace it, turning a pivotal thumb down. Credit... Senate TV, via Reuters

Since he had opposed the Affordable Care Act, Mr. Obama’s signature health care law, Mr. McCain became a critical vote on the Republican bill to repeal and replace it. Written in secret, the Republicans’ bill was opposed by health care and patient advocacy groups. Mr. McCain, fearing his constituents might be harmed, was noncommittal. After struggling to write a passable bill and with no votes to spare, Senator Mitch McConnell of Kentucky, the majority leader, put off a showdown when Mr. McCain was sidelined by surgery for a cranial blood clot over his left eye in July.

ADVERTISEMENT

Senator McCain’s office disclosed that, behind the clot, his doctors had found a glioblastoma, an aggressive and malignant brain tumor. Medical experts said that such cancers may be treated with radiation and chemotherapy but almost always grow back, and that the median length of survival with a glioblastoma is about 16 months.

Days after surgery for the brain cancer, Mr. McCain returned to the Senate and provided a crucial vote for the Republicans to open debate on their efforts to repeal the health law. But when a last-ditch repeal vote was taken later, Mr. McCain made a stirring televised reappearance in the well of the Senate and shocked his colleagues and the nation by turning his thumb down, casting the decisive vote against it.

The seven-year Republican drive to derail the Affordable Care Act had collapsed. Some pundits called the McCain vote cold revenge for Mr. Trump’s mockery of his ordeal as a prisoner of war. But the senator told colleagues that he felt compelled only to “do the right thing.” And in a later statement, he gave a fuller explanation.

[Read John McCain: The last lion in the Senate.]

“The vote last night presents the Senate with an opportunity to start fresh,” he said. “I encourage my colleagues on both sides of the aisle to trust each other, stop the political gamesmanship and put the health care needs of the American people first. We can do this.”

ADVERTISEMENT

In December, Mr. McCain had been expected to be a pivotal vote in the Republican drive to rewrite the nation’s tax code and cut taxes for individuals and businesses by adding up to $1.5 trillion to the federal deficit. Critics of the measure had identified him as a potential holdout against his party’s legislation. Days before the vote, however, Mr. McCain returned home to Arizona for medical treatment, and he did not cast a ballot in the Senate proceedings. But he endorsed the bill, and his support was important, though not decisive, in the Senate’s 51-48 adoption of the tax package.

To the Navy Born

Image Mr. MCain, left, in 1961 with his parents, Roberta Wright McCain and John S. McCain Jr., with a plaque of Mr. McCain’s grandfather, Adm. John Sidney McCain Sr., the patriarch of the military family. Credit... Associated Press

John Sidney McCain III was born on Aug. 29, 1936, at the Coco Solo Naval Air Station in the Panama Canal Zone, one of many posts where his father, John Sidney McCain Jr., served in a long, distinguished Navy career. He was the middle sibling of three children. His mother, born Roberta Wright, was a California oil heiress. His parents eloped to Tijuana, Mexico, to marry in 1933.

With his older sister, Jean Alexandra (who was known as Sandy), and brother, Joseph Pinckney McCain II, John grew up with frequent moves, an often-absent father, a rock-solid mother and family lore that traced ancestral lineages to combatants in every American war and to Scottish clans. There were also highly dubious family claims of having descended from Robert the Bruce, the 14th-century king of the Scots.

ADVERTISEMENT

The patriarch of the 20th-century military family was John’s grandfather, Adm. John Sidney McCain Sr. A pioneer of aircraft carriers, he led many naval and air operations in the Western Pacific in World War II, covering Gen. Douglas MacArthur’s invasion of the Philippines and inflicting heavy losses on the enemy in the war’s final stages. He was in the front row of officers aboard the battleship Missouri in Tokyo Bay when the Japanese signed the documents of surrender in 1945.

John’s father was a decorated submarine commander in World War II. In Washington, the elder Mr. McCain was influential in political affairs as the postwar Navy’s chief information officer and liaison with Congress. Senators, representatives and military brass were often guests at his home. Raised to full admiral, he was the commander of American naval forces in Europe and, from 1968 to 1972, of all American forces in the Pacific, including those in the Vietnam War theater.

(Two Navy destroyers were named McCain, for the senator’s father and grandfather, the first father-and-son full admirals in American naval history.)

Whipsawed by family relocations, young John attended some 20 schools before finally settling into Episcopal High School, an all-white, all-boys boarding school in Alexandria, Va., in the fall of 1951 for his last three years of secondary education. The school, with an all-male faculty and enrollments drawn mostly from upper-crust families of the Old South, required jackets and ties for classes.

ADVERTISEMENT

But the scion of one of the Navy’s most illustrious families was defiant and unruly. He mocked the dress code by wearing dirty bluejeans. His shoes were held together with tape, and his coat looked like a reject from the Salvation Army. He was cocky and combative, easily provoked and ready to fight anyone. Classmates called him McNasty. Most gave him a wide berth.

“He cultivated the image,” Robert Timberg wrote in a biography, “John McCain: An American Odyssey” (1995). “The Episcopal yearbook pictures him in a trench coat, collar up, cigarette dangling Bogey-style from his lips. That pose, if hardly the impression Episcopal sought to project, at least had a fashionable world-weary style to it.”

John and a few friends often sneaked off campus at night to patronize bars and burlesque houses in Washington. He joined the wrestling team — a 127-pound dynamo, he once pinned an opponent in 37 seconds, a school record — and the junior varsity football team, as a linebacker and offensive guard. His grades were abysmal, except in literature and history, his favorite subjects. He graduated in 1954.

That summer, he followed his father and grandfather into the United States Naval Academy in Annapolis, Md. He resisted the discipline. His grades were poor. He stood up to upperclassmen, broke rules and piled up demerits, though never enough to warrant expulsion. But he became a ferocious boxer, a magnet for attractive young women and one of the most popular midshipmen in his class.

ADVERTISEMENT

In the Cockpit

Mr. McCain possessed the rugged independence of a natural leader. It came out at parties and in carousing with friends. Caught by the Shore Patrol at an off-limits bar, he led a carload of drinking buddies in a daring escape. “Being on liberty with John McCain was like being in a train wreck,” one recalled. In 1958, he graduated 894th in his class, fifth from the bottom.

Accepted for flight training, the newly commissioned Ensign McCain learned to fly attack jets at the Naval Air Station in Pensacola, Fla. He also had flings with a succession of young women, from schoolteachers to strippers, and once with a tobacco heiress, “often returning to base just in time to change clothes and drag himself out to the flight line,” Mr. Timberg said.

He liked flying, but his performance was subpar, sometimes careless or even reckless. In the 1960s he crashed in Corpus Christi Bay in Texas and Tidewater, Va., but escaped with minor injuries — and his flying skills improved over time. Early assignments were aboard aircraft carriers: the Intrepid in the Caribbean during the 1962 Cuban missile crisis, and the Enterprise in the Mediterranean.

In 1965, Mr. McCain married Carol Shepp, a model. He adopted her two children, Douglas and Andrew, and they had a daughter, Sidney. After a long separation, the couple were divorced in 1980. He then married Cindy Lou Hensley, a Phoenix teacher whose father owned a beer distributorship. They had two sons, John IV and James, and a daughter, Meghan, and adopted a girl, Bridget, from a Bangladeshi orphanage.

ADVERTISEMENT

Senator McCain’s survivors include his wife; his mother, who is 106; his brother; his sister, Sandy McCain Morgan; his seven children; and five grandchildren.

Image The crew on the carrier Forrestal put out a fire that killed 134 men in the worst noncombat incident in American naval history. Mr. McCain was seriously injured. Credit... U.S. Navy, via Associated Press

Promoted to lieutenant commander in early 1967, Mr. McCain requested combat duty and was assigned to the carrier Forrestal, operating in the Gulf of Tonkin. Its A-4E Skyhawk warplanes were bombing North Vietnam in the campaign known as Operation Rolling Thunder. He flew five missions.

Then, on July 29, 1967, he had just strapped himself into his cockpit on a deck crowded with planes when a missile fired accidentally from another jet struck his 200-gallon exterior fuel tank, and it exploded in flames. He scrambled out, crawled onto the plane’s nose, dived onto a deck seething with burning fuel and rolled away until he cleared the flames.

ADVERTISEMENT

As he stood up, other aircraft and bomb loads exploded on deck. He was hit in the legs and chest by burning shrapnel. At one point, the Forrestal skipper considered abandoning ship. When the fire was finally brought under control, 134 men had been killed.

Despite his misgivings, Mr. McCain volunteered for more missions and was transferred to the carrier Oriskany. On Oct. 26 he took off on his 23rd mission of the war, part of a 20-plane attack on a heavily defended power plant in central Hanoi. Moments after releasing his bombs on target, as he pulled out of his dive, a Soviet-made surface-to-air missile sheared off his right wing.

He ejected as the plane plunged, but hit something as he exited. Both arms were broken and his right knee was shattered. He fell into a lake and, with 50 pounds of gear, sank 15 feet to the bottom, then pulled the inflating pins of his Mae West life jacket with his teeth and rose to the surface, gasping for air. Swimmers dragged him ashore, where he was set upon by a mob.

Image Mr. McCain, center, after he ejected from his fighter plane in 1967 and fell into a lake. The Vietnamese imprisoned and tortured him for more than five years. Credit... Library of Congress

ADVERTISEMENT

Mr. McCain was stripped to his skivvies, kicked and spat upon, then bayoneted in the left ankle and groin. A North Vietnamese soldier struck him with his rifle butt, breaking a shoulder. A woman tried to give him a cup of tea as a photographer snapped pictures. Carried to a truck, Mr. McCain was driven to Hoa Lo, the prison compound its American inmates had labeled the Hanoi Hilton.

There he was denied medical care. His knee swelled to the size and color of a football. He lapsed in and out of consciousness for days. When he awoke in a cell infested with roaches and rats, he was interrogated and beaten. The beatings continued for days. He gave his name, rank and serial number and defied his tormentors with curses.

After two weeks, a doctor, without anesthesia, tried to set his right arm, broken in three places, but gave up in frustration and encased it in a plaster cast. He was moved to another site and tended by two American prisoners of war, who brought him back from near death.

Commander McCain’s prisoner-of-war status was widely reported around the world. Only after his captors learned that his father was an admiral was he given a modicum of medical treatment. Other prisoners said he spoke, incongruously, of someday being president of the United States.

ADVERTISEMENT

Once he was visited by a group of North Vietnamese dignitaries. A prisoner, Jack Van Loan, said Mr. McCain shrieked at them. “Here’s a guy that’s all crippled up, all busted up, and he doesn’t know if he’s going to live to the next day, and he literally blew them out of there with a verbal assault,” Mr. Van Loan told Mr. Timberg. “You can’t imagine the example John set for the rest of the camp by doing that.”

Two Years in Solitary

Image Mr. McCain in 1967 at a hospital in Hanoi, North Vietnam. Only after his captors learned that his father was an admiral was he given medical treatment. Credit... Associated Press

In March 1968, Mr. McCain was put in solitary confinement, fed only watery pumpkin soup and scraps of bread. It lasted two years. When Admiral McCain became the Pacific Theater commander in July, his son was offered early repatriation repeatedly. Commander McCain refused, following a military code that prisoners were to be released in the order taken. He was beaten frequently and tortured with ropes.

Years after his confession to “war crimes” and “air piracy,” Mr. McCain wrote: “I had learned what we all learned over there: that every man has his breaking point. I had reached mine.”

ADVERTISEMENT

His ordeal finally ended on March 14, 1973, two months after the Paris Peace Accords had ended American involvement in the war. The place he had lived longest in his nomadic life was Hanoi. At 36, his hair had gone white. He went home a celebrity, cheered in parades, showered with medals, embraced by President Richard M. Nixon and Gov. Ronald Reagan of California.

For a Navy man who had always tried to live up to his father’s accomplishments, the Silver and Bronze Stars, the Distinguished Flying Cross and other decorations he received were not enough. But a psychiatrist’s report seemed to capture his happiest moment. “Felt fulfillment,” it said, “when his dad was introduced at a dinner as ‘Commander McCain’s father.’ ”

After months of rehabilitation and recovery, he returned to duty and became the Navy’s Senate liaison, as his father had once been. But he knew that his Navy future would be limited by his physical disabilities, and that he would never be an admiral like his forebears. With his mother’s encouragement, he was already thinking about a political career when he retired as a captain in 1981.

Setting his sights on a congressional seat, he settled in Phoenix and became a public relations executive for his father-in-law’s beer distributorship. He developed contacts in the news media and business community, and got to know real estate developers and bankers like Charles Keating Jr.

ADVERTISEMENT

Image In 1982, Mr. McCain, in a campaign partly financed by his wife, easily won a seat in a Republican congressional district in Arizona. Credit... Tom Tingle/Phoenix Gazette, via Associated Press

When Representative John Rhodes of Arizona retired after 30 years in Congress in 1982, Mr. McCain, in a campaign partly financed by his wife, easily won the seat in a Republican district. He embraced President Reagan’s agenda of tax and budget cuts and a strong national defense, but voted to override Mr. Reagan’s veto of sanctions against South Africa for its racist policies. He was re-elected in 1984.

After Senator Barry M. Goldwater decided not to seek re-election as Arizona’s conservative stalwart in 1986, Mr. McCain crushed Richard Kimball, a former Democratic state legislator, for the seat. He won appointments to the Armed Services Committee, the Commerce Committee and the Indian Affairs Committee, and soon gained national attention.

A longtime gambler with ties to the gaming industry, Mr. McCain helped write the Indian Gaming Regulatory Act in 1988, codifying regulations for Native American gambling enterprises. He backed legislation, sponsored by Senators Phil Gramm of Texas and Warren B. Rudman of New Hampshire, for automatic spending cuts in deficit budgets. He was shortlisted as a vice-presidential running mate by the 1988 Republican nominee, George Bush, who won the White House (with Senator Dan Quayle on the ticket).

ADVERTISEMENT

But Mr. McCain’s rising political career was almost upended by scandal. He was one of five senators who took favors from Charles Keating to intercede with federal regulators on behalf of the Lincoln Savings and Loan Association, which collapsed with catastrophic losses. The scandal cost the government and investors billions, and Mr. Keating went to prison for fraud; the so-called Keating Five, cleared of wrongdoing by Senate investigators, were only rebuked for ethical lapses.

In the years that followed, Mr. McCain reinvented himself as a scourge of special interests, crusading for stricter ethics and campaign finance rules, a man of honor chastened by a brush with shame.

The Persian Gulf War in 1991 also helped restore Mr. McCain’s tarnished image. As a television commentator, he showcased his military savvy and impressed Americans as an authoritative voice on foreign policy. While Mr. Bush lost the White House to Bill Clinton in 1992, Mr. McCain easily won re-election.

After years of voting along party lines, Mr. McCain, in the 1990s, emphasized his independence. With the presidency in his distant sights, he challenged Republican leaders and Democrats and was harder to peg politically. He became a self-appointed Republican spokesman on national security — challenging the Clinton administration’s intervention in Somalia, counseling against deploying American troops to the Balkans and sounding an early warning on North Korea’s nuclear ambitions.

ADVERTISEMENT

Mr. McCain was a member of the Select Committee on P.O.W./M.I.A. Affairs, which found “no compelling evidence” that Americans were still alive in captivity in Southeast Asia. (Senator John Kerry, a Democrat and fellow Vietnam War veteran, was the chairman.) Veterans groups and families of long-missing troops rejected the report. He also pressed for full diplomatic relations with Vietnam, which were achieved in 1995.

In the 1996 election, Mr. McCain appeared to be a favorite for the Republican vice-presidential slot, but former Senator Bob Dole, the Republican presidential nominee, chose Jack Kemp, the former congressman and football star. They would lose to Mr. Clinton and Al Gore.

Mr. McCain won re-election to a third term by a landslide in 1998, and a year later he published a memoir, “Faith of My Fathers,” which became a best seller in time for the 2000 election campaign and was later made into a television movie, starring Shawn Hatosy as Mr. McCain.

Smears and Defeat

Image Republican presidential hopefuls, including Mr. McCain, right, before a debate in 1999. The others, from left, were Gary Bauer, Gov. George W. Bush of Texas, Steve Forbes, Sen. Orrin Hatch and Alan Keyes. Credit... Luke Frazza/Agence France-Presse

ADVERTISEMENT

Seeking the 2000 Republican presidential nomination, Mr. McCain pledged “a fight to take our government back from the power brokers and special interests.” Gov. George W. Bush of Texas was favored, but Mr. McCain won the New Hampshire primary, 49 to 30 percent. South Carolina’s primary then loomed as crucial.

It was one of the era’s dirtiest campaigns. Anonymous smears falsely claimed that Mr. McCain had fathered a black child out of wedlock, that his wife was a drug addict and that he was a homosexual, a traitor and mentally unstable. McCain ads portrayed Mr. Bush as a liar and called his religious supporters, the Rev. Jerry Falwell and the televangelist Pat Robertson, “agents of intolerance.”

Mr. McCain later said he regretted calling a Confederate flag on the State Capitol in Columbia a “symbol of heritage.” Civil rights groups had denounced it as a symbol of slavery and oppression of African-Americans. “I feared that if I answered honestly, I could not win the South Carolina primary,” Mr. McCain admitted.

Mr. Bush won the primary and the nomination, and narrowly defeated the Democrat, Vice President Gore, in the general election.

ADVERTISEMENT

[Reflections of John McCain’s decades in public life by reporters and editors at The Times.]

Always wary of an adventurousness that might blind Mr. McCain to potential embarrassments, his advisers grew anxious during the 2000 campaign when a lobbyist, Vicki Iseman, began turning up with him at fund-raisers and at his office. It came to nothing. But a long report in The Times in 2008 said that aides, fearing a romantic involvement, had cautioned Mr. McCain and warned Ms. Iseman off.

The article raised a flap of angry denials, and Ms. Iseman sued the newspaper for libel. The Times did not retract its article but published a note to readers saying it had not intended to suggest a romantic affair, and the suit was dropped.

After the terrorist attacks of Sept. 11, 2001, Mr. McCain supported the Bush administration’s war on terrorism; its invasion of Afghanistan to suppress a fanatic Taliban regime and hunt for Osama bin Laden, the mastermind of the terrorist attacks; and later the invasion of Iraq to depose President Saddam Hussein, the tyrant who was wrongly believed to have weapons of mass destruction.

Image Mr. McCain visiting American troops in Kabul in 2014. He supported the Bush administration’s fight against terrorism after the terrorist attacks of Sept. 11, 2001. Credit... Diego Ibarra Sanchez for The New York Times

ADVERTISEMENT

Rewarded for years of pushing campaign-finance reforms, Mr. McCain and Senator Russ Feingold, Democrat of Wisconsin, finally saw passage in 2002 of the McCain-Feingold Act. It banned a key source of financing for both parties, so-called soft money donated in unlimited amounts to build party strengths, and it limited donations for national candidates to “hard money,” subject to annual limits and other rules. The law’s effects became tangled in lawsuits, court rulings and financing schemes.

As a torture victim, Mr. McCain was sensitive to the detention and interrogation of detainees in the fight against terrorism. In 2005 the Senate passed his bill to bar inhumane treatment of prisoners, including those at Guantánamo Bay, Cuba, by limiting military practices to those permitted by the United States Army Field Manual on Interrogation. His 2008 bill to ban waterboarding as torture was adopted, but vetoed by President Bush.

Mr. McCain wrote six books with his aide, Mark Salter, all with themes of courage. Besides his 2018 memoir, they were “Worth the Fighting For” (2002), “Why Courage Matters: The Way to a Braver Life” (2004), “Character Is Destiny: Inspiring Stories Every Young Person Should Know and Every Adult Should Remember” (2005), “Hard Call: Great Decisions and the Extraordinary People Who Made Them” (2007) and “Thirteen Soldiers: A Personal History of Americans at War” (2014).

In 1993, Mr. McCain gave the commencement address at Annapolis: the sorcerer’s apprentice, home to inspire the midshipmen. He spoke of Navy aviators hurled from the decks of pitching aircraft carriers, of Navy gunners blazing into the silhouettes of onrushing kamikazes, of trapped Marines battling overwhelming Chinese hordes in a breakout from the Chosin Reservoir in North Korea.

ADVERTISEMENT

“I have spent time in the company of heroes,” he said. “I have watched men suffer the anguish of imprisonment, defy appalling cruelty until further resistance is impossible, break for a moment, then recover inhuman strength to defy their enemies once more. All these things and more I have seen. And so will you. I will go to my grave in gratitude to my Creator for allowing me to stand witness to such courage and honor. And so will you.

“My time is slipping by. Yours is fast approaching. You will know where your duty lies. You will know.”

Image Senator John McCain walking from his office to the Senate floor in 2005. Credit... Doug Mills/The New York Times

Correction: Aug. 27, 2018 An earlier version of this obituary omitted the names of three of Mr. McCain’s survivors. In addition to his wife, children and grandchildren, he is survived by his mother, Roberta McCain; a brother, Joseph; and a sister, Sandy McCain Morgan. Aug. 27, 2018

Correction: Aug. 28, 2018 An earlier version of this obituary referred incorrectly to the fire onboard the aircraft carrier Forrestal, on which Mr. McCain served, that killed 134 people. It was not the worst noncombat incident in American naval history; there were several other incidents with higher death tolls. The earlier version also misstated Mr. McCain’s position on the Senate Select Committee on P.O.W./M.I.A. Affairs. He was a member, not a co-chairman. And because of an editing error, the earlier version misstated the league in which the 1996 Republican vice-presidential nominee Jack Kemp had been a star before entering politics. It was the American Football League, not the National Football League. Aug. 28, 2018

Sign up for Breaking News Sign up to receive an email from The New York Times as soon as important news breaks around the world. Sign Up