Sen. John McCain (R-Ariz.) speaks with reporters in the Russell Senate Office Building in 2017 in Washington. (Oliver Contreras/For The Washington Post)

Sen. John McCain, who defied death in the skies over Vietnam, endured years of torture in enemy captivity and embarked on a storied political career that brought him to the precipice of the presidency, has ended medical treatment for the brain cancer he has fought for 13 months, his family said Friday.

“John has surpassed expectations for his survival. But the progress of disease and the inexorable advance of age render their verdict,” the statement said, making clear that McCain’s life is near its end.

The news prompted an outpouring of sympathy and acclaim for McCain, 81, who has served six terms as a Republican senator from Arizona. The tributes came from Republicans and Democrats who had together held out hope that McCain might beat the grim odds posed by his aggressive form of cancer, glioblastoma, and perhaps return to Washington and retake his perch as elder statesman and embodiment of his personal motto: “Country first.”

Instead, McCain’s family and close friends have gathered with him at his family ranch near Sedona, north of Phoenix.

“My family is deeply appreciative of all the love and generosity you have shown us during this past year. Thank you for all your continued support and prayers. We could not have made it this far without you — you’ve given us strength to carry on,” his daughter Meghan McCain, a co-host of ABC’s “The View,” wrote Friday on Twitter.

John McCain took his last vote in the Senate in December, just before a sudden hospitalization and weeks after he had started to become noticeably more frail. But even in absence, McCain hardly withdrew from the public sphere, delivering occasional but stinging rebukes of President Trump — a leader who, during the 2016 presidential campaign, had mocked McCain’s service as a naval aviator and then went on to attack McCain’s 2017 Senate vote that tanked a Trump-backed bill to repeal the Affordable Care Act.

Trump and the White House had no comment Friday.

In his final and perhaps most damning broadside, McCain lambasted Trump’s July news conference alongside Russian President Vladimir Putin in Helsinki — where Trump seemed to put more credence in Putin’s denials than U.S. intelligence findings that Russia interfered in the 2016 election — as “one of the most disgraceful performances by an American president in memory.”

“No prior president has ever abased himself more abjectly before a tyrant,” McCain, the chairman of the Armed Services Committee, said in a statement. “Not only did President Trump fail to speak the truth about an adversary; but speaking for America to the world, our president failed to defend all that makes us who we are — a republic of free people dedicated to the cause of liberty at home and abroad.”

Those notes — of freedom and truth and the duty of Americans to promote it — have been the hallmark of McCain’s political career, born in the early 1980s after the war hero returned home and struggled for a time to find his footing in the shadow of his family’s military legacy.

The son and grandson of Navy admirals, raffish and troublesome before he went to Vietnam, McCain survived two brushes with death there — first, in 1967, during a massive explosion on the USS Forrestal in the Gulf of Tonkin that killed 134, and three months later after being shot down at low altitude over Hanoi, ditching in a lake. Five and a half years of captivity, and frequent torture, followed.

After his release in 1973, McCain undertook a grueling rehabilitation and managed to continue his naval career, regaining his flight credentials and taking command of a combat squadron. But his subsequent service as the Navy liaison to the Senate whetted his interest in politics — and his 1980 marriage to Cindy Hensley, a member of a prominent Phoenix business family, helped give him the opportunity.

Elected to the House in 1982 and then the Senate in 1986, McCain took a keen interest in military and foreign affairs, and largely adopted the Republican Party line on taxes, spending and most policy matters. But he built his reputation for independence by joining with Democrats to pursue campaign finance reform and curbs on the tobacco industry.

Twice, McCain pursued the presidency, falling short in the 2000 GOP primaries to President George W. Bush and in the 2008 general election to President Barack Obama.

In his final months, McCain expressed regret about what could have been. In a book published in May, “The Restless Wave,” he regretted not choosing as his running mate Sen. Joe Lieberman, a former Democratic vice-presidential nominee and close friend, rather than Alaska Gov. Sarah Palin (R).

While McCain made peace with Bush and Obama, his final days are unlikely to include any such reconciliation with Trump.

“For all our disagreements I never doubted President Obama shared the seventy-five-year bipartisan consensus that American leadership of the free world was a moral obligation and a practical necessity,” he wrote in the book. “I’m not sure what to make of President Trump’s convictions.”

McCain’s long-standing maverick streak — and his feud with Trump — have chipped away at his support among one group: conservative Republicans.

A Fox News Channel poll released this week found that McCain had a 52 percent favorable rating nationally, considerably higher than any sitting congressional leader. But more Republicans view him unfavorably than favorably, 48 percent to 41 percent, while Democrats rated him favorably by a 2-to-1 margin.

The bitterness from McCain’s health-care vote — as well as his moderate positions on immigration policy and other conservative priorities — has lingered in Arizona Republican politics. His 2016 primary opponent, former state Sen. Kelli Ward, called on him to resign after his diagnosis was made public last year, and on Friday she again criticized him.

“Obviously our thoughts and prayers are with him,” she said. “It’s unfortunate that he hasn’t been able to be in Washington. He’s missed close to 200 votes.”

McCain’s office has not released a full outline of his memorial services, but friends and advisers have said they expect that there will be services in Phoenix and then Washington, followed by a private burial at the cemetery on the grounds of the Naval Academy in Annapolis.

In “The Restless Wave,” McCain said that he would be buried close to his classmate Charles R. Larson, the late admiral who commanded the Pacific fleet and later served as superintendent of the Naval Academy.

Among those paying tribute Friday was Arizona Gov. Doug Ducey (R), who called McCain an “American hero, always putting country before self.”

It would fall to Ducey to fill any Senate vacancy. Republicans in the state have privately discussed a long list of potential appointees in recent months, including Cindy McCain; Ducey’s chief of staff, Kirk Adams; state treasurer Eileen Klein; and former U.S. senator Jon Kyl.

Among McCain’s colleagues on Capitol Hill, Senate Majority Leader Mitch McConnell (R-Ky.) wrote on Twitter: “Very sad to hear this morning’s update from the family of our dear friend @SenJohnMcCain. We are so fortunate to call him our friend and colleague. John, Cindy, and the entire McCain family are in our prayers at this incredibly difficult hour.”

Sen. Amy Klobuchar (D-Minn.), who visited McCain last month, said, “John is a fighter, and I know he is facing this difficult time with the same bravery he has shown his entire life. I am grateful for his friendship and for his service.”

Brain tumor experts said that because the prognosis for glioblastoma patients is so poor — median survival is just 18 months — many patients eventually face the difficult decision of when to end treatment.

That decision can be influenced not only by the course of the disease but also by the quality of life — depending on the location of the tumor, the patient can lose the ability to speak, walk and see — and whether the treatment is helping or hurting the patient.

“Most patients do ultimately have to deal with this,” said John de Groot, a neuro-oncologist at M.D. Anderson Cancer Center in Houston. “At some point, all existing therapies have been tried, and sometimes experimental ones have been tried, and despite that, the tumor continues to grow. The tumor burden becomes so great that doing anything additional becomes futile.”

After a patient decides to end treatment, the survival time varies from two to perhaps six weeks, depending on the stage of disease, de Groot said.

A close friend, former senator Christopher J. Dodd (D-Conn.), said the decision reflected “classic McCain.”

“John obviously demonstrated incredible courage many decades ago, and it’s not surprising that he would reach that decision, to forego medical treatment to sustain something that’s unsustainable,” he said.

Scott Clement, Laurie McGinley, Avi Selk and Erica Werner contributed to this report.