Mr. McCain once told a Navy psychiatrist that, as a teenager, he was a “rebel without a cause.” One of his high school nicknames was “McNasty.” Even today, some congressional colleagues call him “Senator Hothead”; more than a few have received letters of apology from Mr. McCain after being told off by him, sometimes loudly and profanely.

That struggle between niceness and harshness was evident during Mr. McCain’s 2008 run for president. That year, groups that were nominally independent from the Republican Party bought advertisements meant to (however subtly) stir a racist backlash against Barack Obama. Mr. McCain might have stood back and let them do his dirty work; instead he quietly, firmly let it be known he and his campaign wanted no such underhanded tactics. When a woman at a rally attacked Mr. Obama as an “Arab,” Mr. McCain responded, “No, ma’am, no, ma’am, he’s a decent, family-man citizen.”

This was the same McCain who, as he anxiously watched a nascent Tea Party movement take root in his party, chose Sarah Palin to be his running mate. In the process, he ended up sabotaging his own campaign; worse, Ms. Palin’s know-nothing rants helped set the stage for Mr. Trump. (Does Mr. McCain regret his choice? “McCain looks forward, not back,” a friend of his told me.)

Mr. McCain has had a similarly complicated record in the Senate. He has shown an ability to reach across the aisle, working with Senator Edward Kennedy on the last serious congressional attempt at immigration reform. He even cooperated from time to time with Senator Hillary Clinton (and in 2004, on a trip to Estonia, engaged her in a vodka-drinking contest). But he can be extremely, immoderately partisan. Just last week, he blurted on talk radio that if Mrs. Clinton is elected, he will try to block any Supreme Court nominee she sends to Congress. (A spokesman later tried to walk back this reckless vow.)

And yet, as a defeated presidential candidate in 2008, he showed grace and respect for democracy. “This campaign was and will remain the great honor of my life,” he said on election night, “and my heart is filled with nothing but gratitude for the experience and to the American people for giving me a fair hearing before deciding that Senator Obama and my old friend Joe Biden should have the honor of leading us for the next four years.”

On his 23rd mission over North Vietnam, Captain McCain heard the beep signaling that an antiaircraft missile had locked on to his plane. He could have “jinked” — aborted the mission — to avoid the missile, but out of stubborn bravery, he flew straight on. He had just toggled the bomb-release switch when the enemy missile blew off the right wing of his plane.