Washington (AFP) - A nearly weeklong celebration of the life of US senator John McCain -- war hero, maverick, two-time presidential candidate and outspoken critic of Donald Trump -- came to a solemn and subdued end Sunday as he was laid to rest at the US Naval Academy in Annapolis, Maryland.

McCain, who died August 25 aged 81 after a year-long struggle against brain cancer, was interred in a private ceremony in the academy's grassy cemetery overlooking the Severn River.

McCain, the son and grandson of four-star admirals, graduated from the naval academy in 1958.

Large crowds lined the road to pay their respects as the funeral cortege carrying McCain's flag-draped casket passed by. Some saluted or held signs paying tribute. One woman shouted out, "God bless America!"

"I watched them lay my friend to rest today. I will miss him," Senator Jeff Flake tweeted Sunday along with a photo of him and McCain, in which the former pilot wore a Navy hat.

A day after a nationally televised memorial service at Washington's National Cathedral brought together a remarkable gathering of luminaries from both parties -- including three former presidents, but not the current one -- Sunday's ceremony was designed more as a family affair, including the military family to which McCain proudly belonged.

His casket was taken to the Naval Academy's chapel for a private ceremony, at which General David Petraeus, Senator Lindsey Graham and McCain's son Jack delivered tributes.

Pallbearers included US defense secretary James Mattis; rear admiral and former naval academy superintendent Thomas Lynch; Admiral John Richardson; and two men -- Everett Alvarez Jr. and Jon Fer -- who were prisoners of war in Vietnam along with McCain.

- Buried alongside best friend -

The casket was then carried to its final resting place by a horse-drawn caisson, with white-clad US Navy personnel lining the road and saluting as it passed, according to photos released by McCain's family.

Story continues

The senator was buried next to his best friend from Annapolis days, Chuck Larson, who died in 2014. Larson and McCain were roommates through navy flight school, and Larson went on to become the second-youngest admiral in navy history and an academy superintendent.

McCain, a lifelong rebel who graduated near the bottom of his class, had planned a military career. But after his fighter jet was shot down over Vietnam, leaving him with lifelong injuries, he ultimately left the military and turned to politics, representing Arizona in the US Congress for 35 years.

He ran unsuccessfully for president twice, in 2000 and 2008.

The week's memorials, planned mostly by McCain himself in his final year of life, often seemed crafted to draw a contrast between the senator and a man of very different temperament and values with whom he often feuded: Donald Trump.

The president, pointedly excluded from all the McCain events, had a difficult week.

He was widely criticized for keeping White House flags at half staff for only a day, and then reversed the order. A new Washington Post/ABC poll showed Trump's disapproval rating at an all-time high of 60 percent. And critics panned him for playing golf during Saturday's solemn event.

In Annapolis, Sam Smith, a 71-year-old retired federal employee, was among those saluting McCain's cortege as it passed.

"We just feel that he's somebody we admire," he told the Capital Gazette of Annapolis. "He was always a champion of the people."