Sen. John McCain, who survived nearly six years as a prisoner of war in North Vietnam, succeeded Barry Goldwater to represent Arizona in the Senate, lost a White House bid to freshman Sen. Barack Obama and became an outspoken critic of President Donald Trump, has died. He was 81.

McCain died Saturday. His office released this statement:

Senator John Sidney McCain III died at 4:28pm 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.

Later, Cindy McCain took to Twitter to honor her husband.

"My heart is broken. I am so lucky to have lived the adventure of loving this incredible man for 38 years," she tweeted. "He passed the way he lived, on his own terms, surrounded by the people he loved, in the the place he loved best."

Daughter Meghan McCain posted a tribute to her father on social media, as well.

McCain was diagnosed in July 2017 with glioblastoma, a virulent brain cancer, a week after doctors removed a blood clot from above his left eye. He underwent surgery for an intestinal infection in April 2018.

On Aug. 24, five days before his 82nd birthday, his family announced that "with his usual strength of will, he has now chosen to discontinue medical treatment.

"Our family is immensely grateful for the support and kindness of all his caregivers over the last year, and for the continuing outpouring of concern and affection from John's many friends and associates, and the many thousands of people who are keeping him in their prayers," the family said. "God bless and thank you all."

During his 3½-decade congressional career, McCain was a conservative who rejected Republican orthodoxy, earning him the label "maverick." He backed campaign finance reform to limit corporate donations to candidates and was a leader in efforts to normalize relations with Vietnam. He voted against a bill to make Martin Luther King's birthday a federal holiday but backed legislation to support his Native American constituents, including the 1988 Indian Gaming Regulatory Act, which opened the way for tribal casino development. And he was a thorn in the side of fellow Republican Trump, who expressed his "deepest sympathies to McCain's family about his passing.

His treatment forced him to miss the Senate vote on the GOP tax overhaul in December 2017. But nearly two weeks after surgery in July 2017, he marched into the Senate to a standing ovation and cast the deciding vote that killed the Senate GOP's "skinny" bill to repeal Obamacare — at 1:29 a.m. He joined with Republican Sens. Lisa Murkowski of Alaska and Susan Collins of Maine and 48 Democrats.

"From the beginning, I have believed that Obamacare should be repealed and replaced with a solution that increases competition, lowers costs, and improves care for the American people. The so-called 'skinny repeal' amendment the Senate voted on today would not accomplish those goals," McCain said in a statement. "We must do the hard work our citizens expect of us and deserve."

Bill O'Leary | The Washington Post | Getty Images

Sen. John McCain makes his way to a meeting on the tax bill in the Senate, Dec. 1, 2017.

Trump never forgave him. In signing what Congress called the John S. McCain National Defense Authorization Act for Fiscal Year 2019, the president omitted the senator's name while reading the title of the bill at the August 2018 ceremony.

A month earlier, McCain blasted Trump for his performance at the news conference with Russian President Vladimir Putin following the U.S.-Russia summit. "Today's press conference in Helsinki was one of the most disgraceful performances by an American president in memory," McCain said. "He and Putin seemed to be speaking from the same script as the president made a conscious choice to defend a tyrant against the fair questions of a free press, and to grant Putin an uncontested platform to spew propaganda and lies to the world."

Two months after the 2017 Obamacare vote, McCain spoke about his fight with brain cancer, including his radiation and chemotherapy treatments that started his day.

"I am more energetic and more engaged as a result of this because I know that I've got to do everything I can to serve this country while I can," McCain told CBS' "60 Minutes."

Concerns were raised about McCain's health in June 2017, during former FBI Director James Comey's testimony before the Senate Intelligence Committee. At the hearing, McCain asked questions that apparently conflated the investigations of Russian meddling in the 2016 election with the probe of Hillary Clinton's email practices. Two of his statements also confused Trump and the fired FBI director.

After the cancer diagnosis a few weeks later, messages of support came pouring in from friends and foes alike. Even Trump, who during the 2015 presidential campaign said McCain was "not a war hero" because he had been captured by North Vietnam, tweeted well-wishes.

On Saturday, Obama and his wife, former first lady Michelle Obama, paid tribute to McCain.

"Few of us have been tested the way John once was, or required to show the kind of courage that he did. But all of us can aspire to the courage to put the greater good above our own," the Obamas wrote in a statement. "At John's best, he showed us what that means. And for that, we are all in his debt."

It wasn't McCain's first fight against cancer. He underwent surgery in 2000 for melanoma on his face, leaving him with a puffy left jaw.

Getty Images

Sen. John McCain announces his opposition to the "skinny repeal" of Obamacare, July 27, 2017.

Two runs for the White House

McCain's Senate tenure began in 1987, when he succeeded the retiring Goldwater, the GOP's 1964 presidential candidate.

In McCain's 2008 run for the White House, he made a "Hail Mary" pick for a running mate, Alaska Gov. Sarah Palin, in hopes that a woman on the ticket would energize his flagging campaign. Obama won by 53 to 46 percent.

McCain had considered independent Sen. Joe Lieberman as his running mate. Aides advised against it because Lieberman, who was Al Gore's running mate in their failed 2000 race against George W. Bush and Dick Cheney, still caucused with the Democrats and supported abortion rights.

"John McCain was my friend. I will remember the good times. My family and I send prayers for Cindy and the McCain family," the former vice presidential nominee wrote.

McCain also ran in 2000, winning only Arizona and six other states in his bid for the GOP nomination that was won by Bush.

Bush paid tribute to McCain on Saturday, not long after the senator's death was announced.

"Some lives are so vivid, it is difficult to imagine them ended. Some voices are so vibrant, it is hard to think of them stilled. John McCain was a man of deep conviction and a patriot of the highest order," the former president said in a statement. "He was a public servant in the finest traditions of our country. And to me, he was a friend whom I'll deeply miss."

A hawk on foreign policy, McCain became chairman of the Senate Armed Services Committee after Republicans took control of the chamber in 2015.

He made his first foray into politics in 1982 by winning the seat left vacant by the retirement of House Minority Leader John Rhodes. McCain served two terms before being elected to the Senate.

In the late 1980s, he was one of the "Keating Five" senators accused of improperly intervening on behalf of Phoenix savings and loan executive Charles Keating in an investigation by the Federal Home Loan Bank Board. McCain, whose campaigns had received $112,000 in donations from the S&L executive, sat in on two meetings with the regulators in the Keating matter. After an extensive investigation by the Senate Ethics Committee, McCain was exonerated in 1991 but reprimanded for using "poor judgment."

''It was a searing experience for John,'' attorney John Dowd, who represented him during the ethics inquiry (and later served nine months as Trump's lawyer in the probe of Russian meddling in the 2016 presidential campaign), told The New York Times in 1999. ''He told me it was worse than being in Hanoi.''

The son and grandson of four-star admirals, John Sidney McCain III was born Aug. 29, 1936, at a Navy air station in the Panama Canal Zone. He graduated from the U.S. Naval Academy in 1958, was commissioned as an ensign and became a Navy aviator.

Surviving the 'Hanoi Hilton'

McCain was an A-4 Skyhawk pilot stationed on the USS Forrestal when the aircraft carrier caught fire off Vietnam on July 29, 1967 — its fifth day of combat duty — killing 134 servicemen. During a bombing run over Hanoi five months later, he was shot down, parachuting into a lake. While ejecting from the plane flying at 575 mph, he was knocked unconscious, breaking a knee and both arms, according to his account published in U.S. News & World Report.

After being dragged out of the lake by the North Vietnamese, he recalled, he survived a mob attack and was taken to the Hoa Lo Prison — derisively dubbed the Hanoi Hilton. After being interrogated, beaten and bayoneted in a foot, he was denied medical care until his captors found out he was the son of an admiral. They took him to a hospital.

Reuters

After his plane was shot down, McCain is pulled out of a Hanoi lake by North Vietnamese soldiers and civilians in this October 1967 file photo.

"I woke up a couple of times in the next three or four days," McCain wrote. "Plasma and blood were being put into me. I became fairly lucid. I was in a room which was not particularly small — about 15 by 15 feet — but it was filthy dirty and at a lower level, so that every time it rained, there'd be about a half inch to an inch of water on the floor. I was not washed once while I was in the hospital. I almost never saw a doctor or a nurse."

He was held until 1973, including more than two years in solitary confinement. He estimated that at one point during his captivity, his weight had dropped to 105 pounds.

"I thought a lot about the meaning of life," he said in his U.S. News recollection written in 1973.

"As prisoners of war in North Vietnam, deprived of all liberty, we relied on three things: faith in God, faith in our country, and faith in each other," McCain wrote in the forward to the 2017 book "Six Years in the Hanoi Hilton" by Amy Shively Hawk, daughter of POW James Shively. "Reliance on those three ideologies forged within us a special unity and loyalty. Forty-two years later, those I love most and best in the world are men I spent time with in prison."

He returned to Vietnam several times, first in 1985 to commemorate the 10th anniversary of the end of the war, and in April 2000 to mark the 25th anniversary. Referring to the prison guards, he told The New York Times during that visit: ''I still bear them ill will, ... not because of what they did to me, but because of what they did to some of my friends — including killing some of them.''

'I have faced tougher adversaries'

Before the July 28 vote against the Obamacare repeal, McCain's absence from Washington due to the brain surgery at the Mayo Clinic in Phoenix helped set back the Republicans' previous attempt to repeal and replace Obama's Affordable Care Act, given the GOP's tiny edge in the Senate.

That announcement prompted Trump to blame him for the GOP failure to repeal Obamacare.

"You can call it what you want, but that's the only reason we don't have it, because of John McCain," Trump said in September 2017 on the "Rick and Bubba" radio show, which airs in the South.

Receiving the Liberty Medal at the National Constitution Center in Philadelphia the next month, McCain took issue with the nationalist and isolationist policies that Trump campaigned on to win the White House. Without mentioning Trump by name, McCain said:

"To fear the world we have organized and led for three-quarters of a century, to abandon the ideals we have advanced around the globe, to refuse the obligations of international leadership and our duty to remain 'the last best hope of earth' for the sake of some half-baked, spurious nationalism cooked up by people who would rather find scapegoats than solve problems is as unpatriotic as an attachment to any other tired dogma of the past that Americans consigned to the ash heap of history."

Trump responded in an interview with Washington's WMAL radio, saying: "I'm being very, very nice, but at some point I fight back and it won't be pretty."

'This guy, he served his country'

McCain married former swimsuit model Carol Shepp in 1965. He adopted her two children, and the couple had a daughter, Sidney in September 1966.

During his captivity, his wife crashed her car while visiting her family. She was severely injured in the Christmas Eve 1969 crash but was able to keep her injuries out of the media so that her POW husband wouldn't find out.

After his release, their marriage faltered and the couple divorced in 1980 but maintained an amicable relationship. She later worked in the Reagan White House.

A month after the divorce, McCain married Cindy Lou Hensley, a special education teacher and Arizona beverage heiress. She gave birth to their daughter, Meghan, in 1984, and to sons John Sidney IV in 1986 and James in 1988. Five years later, they adopted a fourth child, Bridget, whom they first met while she was living at Mother Teresa's orphanage in Dhaka, Bangladesh.

While co-host of ABC's "The View," Meghan McCain had a tearful on-air encounter in December 2017 with Vice President Joe Biden, whose son Beau died of glioblastoma in 2015.

"I think about Beau almost every day and I was told — sorry — that this doesn't get easier, but that you cultivate the tools to work with this and to live with this," she told Biden through tears as her father was hospitalized at Walter Reed Medical Center.

"America will miss John McCain. The world will miss John McCain. And I will miss him dearly," Biden said in a statement.

In the September 2017 interview on "60 Minutes," McCain said the devastating brain cancer diagnosis made him appreciate his life.

"I have feelings sometimes of fear of what happens. But as soon as I get that, I say, 'Wait a minute. Wait a minute. You've been around a long time, old man. You've had a great life,'" he told CBS.

"You just have to understand that it's not that you're leaving. It's that you ... stayed. I celebrate what a guy who stood fifth from the bottom of his class at the Naval Academy has been able to do. I am so grateful. I, every night when I go to sleep, I am just filled with gratitude."

In the interview, he expressed a wish for a memorial service at Annapolis. "I want, when I leave, that the ceremony is at the Naval Academy, and we just have a couple of people that stand up and say, 'This guy, he served his country.'"