“Many of us wish we had the courage to have played the role John McCain played,” said Connie Mack III, a Florida Republican who entered the House with Mr. McCain in 1983 and later served with him in the Senate.

There was no small amount of political intrigue at the ceremony as those attending noted carefully who was on hand from the Trump administration — Attorney General Jeff Sessions, a former senator now under intense fire from the president; Rod J. Rosenstein, the No. 2 at the Justice Department and the official responsible for the special counsel inquiry; the chief of staff, John F. Kelly; the president’s counselor, Kellyanne Conway; and a retinue of national security officials whose ties to Mr. McCain go much deeper than with Mr. Trump.

Many on hand stole glimpses of the Trump officials as the ceremony proceeded.

“What a lot of drama,” said one current senator who preferred not to be named discussing the atmospherics of such a solemn event. But that was another aspect of the service that would have appealed to Mr. McCain, himself the instigator of much Capitol Hill drama over the years.

Vice President Mike Pence, who in his job also serves as president of the Senate, represented the White House and took pains to point out that “the president asked me to be here on behalf of a grateful nation to pay a debt of honor and respect to a man who served our country throughout his life, in uniform and in public office.”