The Republican senator from Arizona literally lived the nation's history — from turbulent days of the Vietnam War era to the tumultuous times of the Trump administration.

McCain was praised by admirers as a true American hero and by detractors and supporters alike as a man who stood by his beliefs.

Here's a look at the life and times of John Sidney McCain III through pictures.

Navy aviator

McCain graduated from the U.S. Naval Academy in 1958 and was commissioned as an ensign. In this 1965 photo, he poses with his Navy squadron. Two years later, he survived the June 29, 1967, fire on the USS Forrestal that killed 134 servicemen.

National Archives | Reuters

Shot down

McCain is pulled out of a Hanoi lake by North Vietnamese Army troops and Vietnamese citizens in this October 1967 photo. After his A-4E Skyhawk was shot down by a missile, McCain said, "I pulled the ejection handle, and was knocked unconscious by the force of the ejection — the air speed was about 500 knots."

Reuters

POW in Vietnam

After being interrogated, beaten and bayoneted in a foot, McCain recalled, he was denied medical care until his captors found out he was the son of an admiral. They then took him to a hospital, where this picture was taken. He was a POW for nearly six years in places including the notorious "Hanoi Hilton."

Bettman Collection | Getty Images

A war hero comes home ...

As part of the negotiations to end the war, McCain was among the U.S. prisoners released by North Vietnam in 1973 under Operation Homecoming. In this photo, McCain is greeted by President Richard Nixon in Washington, May 24, 1973.

National Archives | Reuters

... and goes to Capitol Hill

McCain entered 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 1987, succeeding Barry Goldwater. In this photo, Vice President George H.W. Bush re-enacts the swearing-in of McCain as the family of the newly elected senator from Arizona looks on.

Cynthia Johnson | The LIFE Images Collection | Getty Images

Keating Five

In the late 1980s, McCain 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 a 14-month investigation, the Senate Ethics Committee exonerated him in 1991 but reprimanded him for using "poor judgment."

Terry Ashe | The LIFE Images Collection | Getty Images

Presidential hopeful

McCain first ran for president in 2000 but pulled out in the race for the GOP nomination on May 9, 2000. In this photo, he and then-Texas Gov. George W. Bush joked at a news conference in Pittsburgh, where McCain endorsed his former political rival.

Jason Cohn | Reuters

McCain revisits the 'Hanoi Hilton'

McCain returned to Vietnam several times. Marking the 25th anniversary of the end of the war, McCain visited the "Hanoi Hilton" in April 2000. In this photo, he steps down a dark corridor separating jail cells, followed by his son Jack. During the visit, McCain said he could not forgive the jailers who mistreated and killed his comrades.

Jason Reed | Reuters

Maverick runs again

In 2008, McCain made a second run for the White House, eventually losing to a freshman Democratic senator from Illinois — Barack Obama. On Aug. 29, 2008, one day after the Democrats nominated the first African-American presidential candidate, Republican McCain selected Alaska Gov. Sarah Palin as his pick for vice president in hopes of energizing his flagging campaign. In this photo, he introduces Palin as his running mate.

Mario Tama | Getty Images

Political rivals meet

McCain meets with the then-president-elect at Obama's transition office in Chicago on Nov. 17, 2008.

Getty Images

Health-care repeal

In this December 2009 photo, McCain and Senate Minority Leader Mitch McConnell, R-Ky., appear at a news conference to talk about repealing the Affordable Care Act. More than seven years later, in July 2017, McCain cast the decisive vote that killed one of the GOP's attempts to repeal and replace Obamacare. "I thought it was the right thing to do," the maverick McCain said.

Scott J. Ferrell | Congressional Quarterly | Getty Images

Brain cancer and health care

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

Getty Images

Hero's medal

Former Vice President Joe Biden presents McCain with the Liberty Medal at the National Constitution Center in Philadelphia in October 2017. At the ceremony, 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."