John McCain, the military hero who had a long career as a "maverick" Republican senator, has died, his Senate office confirmed on Saturday. He was 81.

In a statement, his Senate office said he died at 4:28 p.m. on August 25, surrounded by his wife Cindy and his family.

McCain was diagnosed with glioblastoma, an aggressive form of brain cancer, in July 2017. On August 24, McCain's family said that "with his usual strength of will," he had chosen to discontinue treatment. Though McCain had "surpassed expectations for his survival, … the progress of disease and the inexorable advance of age render their verdict," the statement said.

In September, the Arizona senator told Lesley Stahl on "60 Minutes" that he didn't believe the diagnosis changed him, and while he sometimes felt moments of fear, he hoped a simple legacy would endure.

Get Breaking News Delivered to Your Inbox

"As soon as I get that [fear], I say, 'Wait a minute. Wait a minute. You've been around a long time, old man. You've had a great life. You've had a great experience,'" McCain said. "I want – 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.'"

Early life and Vietnam

The son and grandson of admirals, John Sidney McCain was born at a U.S. Naval base in Panama on August 29, 1936. After moving with his parents from base to base, then to boarding school, he attended the Naval Academy at Annapolis and graduated to become a Navy pilot. He frequently joked about his poor performance in school, calling himself an "undistinguished member of the Class of 1958" in a 2017 speech to U.S. Naval Academy graduates.

"To be honest, I wasn't too thrilled to be here back then, and I was as relieved to graduate – fifth from the bottom of my class – as the Naval Academy was to see me go," McCain said.

McCain married Carol Shepp in 1965, and adopted her two young sons. A daughter, Sidney, was born soon after.

He volunteered to fly combat missions in Vietnam in 1967, and narrowly escaped death during a fire aboard the USS Forrestal that killed 134 of his shipmates. Just months later, McCain, then a lieutenant commander, was shot down during a bombing run over North Vietnam. Already wounded, he was found and captured by enemy forces, who refused him medical treatment and stabbed him with a bayonet.

While holding him as a prisoner of war, the North Vietnamese tried to exploit the fact that his father was a prominent admiral at the time. They offered McCain an early release. But he refused, adhering to the military code of "first in, first out." McCain was finally freed after five-and-a-half years, two of which he spent in solitary confinement. He limped off the plane that returned him to the U.S. gripping a handrail and with hair that had turned white, according to a New York Times report from 1973 on his release. The injuries he sustained would affect his mobility for the rest of his life.

A young husband and father when he left for Vietnam, he separated from Carol soon after his return.

U.S. Navy Lt. Commander John S. McCain III returned to the United States in 1973, after having spent more than five years as a prisoner of war in Hanoi. His fellow prisoners called him a hero, for his refusal to accept release ahead of POWs who had been there longer. More than three decades later, even his political rivals call him a hero. It is a word McCain uses often, but never about himself. AP

Months after formally separating from Carol, McCain married Cindy Hensley, 17 years his junior and the daughter of the founder of Hensley & Company, the dominant beer wholesaler in Arizona.

Married for 38 years, John and Cindy McCain went on to have four children: Meghan, James, Jack and Bridget.

Elected to Congress

Elected to the U.S. House of Representatives in 1982 as a conservative Republican, McCain was broadly supportive of President Ronald Reagan's agenda. He was also considered to be one of the most popular members of the freshman class of 1983.

"John was clearly the star from the first day," Steve Bartlett, a former congressman from Texas, told The New York Times in 2008.

In 1986, he ran for and won the seat of the retiring Arizona Sen. Barry Goldwater, whose 1964 run for the Republican nomination presaged the rise of conservatism in American politics.

He may have become famous for his "straight talk," but McCain's first term was marred by the savings and loan scandal, in which it was revealed that he had accepted over $100,000 in contributions from disgraced financier Charles Keating Jr., the chairman of Lincoln Savings and Loan Association.

McCain and four Democratic senators had received over $1 million in campaign contributions from Keating. They were nicknamed "the Keating Five" for their involvement and investigated by a Senate ethics committee. In 1991, the committee ruled that McCain's actions "were not improper nor attended with gross negligence."

Senator John McCain (L), R-Arizona, smiles as he chats with US Senator Ted Kennedy, D-MA, before an Emerging Threats and Capabilities Subcommittee hearing on detainee trails in light of the US Supreme Court ruling Hamdan vs. Rumsfeld on Capitol Hill in Washington, D.C., on July 19 2006. Getty

The experience shook but did not hobble McCain's political career, and in the end the Senate Ethics Committee cleared him of any wrongdoing. But he still nearly lost his 1992 re-election bid, and later wrote in his 2002 memoir about his dismay at being perceived as "one of the crooked senators who had bankrupted the thrift industry." The experience led him to become one of the leading proponents of campaign finance reform, an effort that was opposed by the bulk of his party.

"I faced in Vietnam, at times, very real threats to life and limb," McCain told The Associated Press in 2008. "But while my sense of honor was tested in prison, it was not questioned. During the Keating inquiry, it was, and I regretted that very much."

Presidential runs

The quotable and charismatic McCain developed a reputation as a maverick in the Senate, and seemed to relish his fights with the GOP establishment. He was at times unorthodox in his views, much to the consternation of his party's leadership, although his reputation for straight talk helped propel his run for the Republican presidential nomination in 2000.

McCain entered the race an underdog, with most of the party's leading figures quickly moving to embrace then-Texas Gov. George W. Bush. The primary fight was personally and politically brutal, particularly after McCain won New Hampshire. Bush allies unleashed a no-holds-barred attack on the Arizona senator during the critical South Carolina primary. Nasty political rumors suggested that the McCains' young daughter Bridget, who was adopted from Bangladesh, was his illegitimate black child. McCain's older daughter, Meghan, said in 2008 "I don't know if I'll ever completely get over it."

Bush won the contest, and McCain eventually dropped out and endorsed his rival.

Republican presidential hopeful Sen. John McCain, R-Ariz., addresses supporters on election night in Nashua, N.H., Tuesday, Jan. 8, 2008. McCain won the New Hampshire Republican primary, completing a remarkable comeback and climbing back into contention for the presidential nomination. AP

Returning to the Senate, McCain helped push through the McCain-Feingold campaign finance reform bill in 2002 despite widespread Republican opposition. In the wake of 9/11, he publicly condemned the rough interrogation techniques implemented by the Bush administration as "torture." But he backed President Bush's plan for a troop surge in 2006 when it was unpopular with the American public.

"I disagree with what the majority of the American people want," McCain said at the time. "Withdrawal will lead to chaos."

The surge would later be praised for rescuing the American effort in Iraq from disaster.

In 2008, McCain -- then older than any first-term president in history at age 71 -- once again ran for the Republican presidential nomination.

US Republican presidential candidate John McCain (C) speaks during a rally Nov. 1, 2008, in Springfield, Va., with his wife Cindy (R) and daughter Meghan (L). Getty

His general election opponent, freshman Illinois Sen. Barack Obama, ran on a platform of "hope and change" that widely resonated with the electorate. And McCain's fortunes were not bolstered by his selection of Sarah Palin, Alaska's polarizing and unpolished governor.

Obama beat McCain by a two-to-one electoral college margin.

McCain kept his trademark sense of humor after the loss, joking to Stephen Colbert in 2015 that "after I lost, I slept like a baby. Sleep two hours, wake up and cry, sleep two hours, wake up and cry."

The Trump era

McCain returned to the Senate and remained outspoken. Over the last three years, Donald Trump became a frequent target.

After McCain said a Trump campaign rally in Phoenix "fired up the crazies," Mr. Trump hit back with an infamous comment about McCain's military service.

"He's not a war hero," Mr. Trump said at an event in Iowa in 2015. "He's a war hero because he was captured. I like people that weren't captured, OK?"

McCain told "60 Minutes" that Mr. Trump never apologized for his comments, and McCain said he would be "glad to converse with him." But McCain noted they were "very different people. Different upbringing. Different life experiences."

"He is in the business of making money and he has been successful both in television as well as Miss America and others," McCain said. "I was raised in a military family. I was raised in the concept and belief that duty, honor, country is the – is the lodestar for the behavior that we have to exhibit every single day."

Senate Intelligence Committee member Sen. John McCain, R-Arizona, heads into a closed-door committee meeting with Director of National Intelligence Dan Coats in the Hart Senate Office Building on June 15, 2017 in Washington, D.C. According to committee Chairman Richard Burr, R-North Carolina, Coats met with the committee for four hours to follow up to his testimony from a week earlier and to discuss the FY2018 budget. Getty

After the campaign was over, the president and McCain continued to clash, perhaps most notably over the repeal of the Affordable Care Act.

McCain dealt with a number of health issues over the years, including the lingering effects of his Vietnam War injuries and several recurrences of the skin cancer melanoma. Surgery for a blood clot in the summer of 2017 led to a diagnosis of glioblastoma, an aggressive form of brain cancer. He remained optimistic about his prognosis, saying he had "faced other challenges" and was "very confident about getting through this as well."

Just a week after revealing his cancer diagnosis, McCain had another surprise for the American people. He returned to a standing ovation on the Senate floor in the midst of the heated debate over repealing President Obama's signature health care legislation, the Affordable Care Act. McCain called the warm reception "deeply moving," but proceeded to deliver a blistering speech condemning his colleagues for the dysfunctional way the Senate had been operating.

Three days later, when the bill came to a vote, McCain broke with his party and voted against it, delivering a "thumbs down" gesture in a dramatic late-night session. His vote ultimately sunk the bill.

In the statement released after the vote, McCain urged his colleagues to "return to the correct way of legislating and send the bill back to committee, hold hearings, receive input from both sides of aisle, heed the recommendations of nation's governors, and produce a bill that finally delivers affordable health care for the American people."

It was one last call for honor from a man who had been raised to put "duty, honor, country" first.

"I celebrate what a guy who stood fifth from the bottom of his class at the Naval Academy has been able to do," McCain said. "I am so grateful. I – every night when I go to sleep, I am just filled with gratitude."