Ted Kennedy liked to tell a favorite story about Sen. John McCain.

The Massachusetts Democrat and the Arizona Republican were on the floor of the Senate and became distracted by a heated debate between two freshmen senators. Just for the fun of it, Kennedy and McCain launched into the fray.

As one spoke, the other circled the chamber, pretending to be agitated. They bellowed away at each other. Finally, they scared the freshman senators off the floor, leaving them unsure why their legendary colleagues had ever joined the debate on an issue neither particularly cared about.

At that, Kennedy and McCain went back to doing what they did best, mastering the Senate and crafting a bipartisan deal that would overwhelm the opposition.

“Ted and I shared the sentiment that a fight not joined was a fight not enjoyed,” McCain said during a speech seven years ago inside Boston’s John F. Kennedy Presidential Library.

Then-Sens. Barack Obama (D-Ill.) and Ted Kennedy (D-Mass.) appear with Sen. John McCain (R-Ariz.) after a Senate immigration bill passed in May 2006. (Melina Mara/The Washington Post)

He was delivering a eulogy at the memorial service of “my friend Ted,” days after Sen. Edward M. Kennedy had succumbed to a form of brain cancer known as glioblastoma.

Sometimes fierce opponents, sometimes mischief-making partners, Kennedy and McCain helped define what the modern Senate could be, or at least should be.

Now, their shared bond has taken a brutal turn: McCain has been diagnosed with the same brain cancer that cut Kennedy’s life short at 77. The Arizonan’s office announced that he is considering several medical options, including chemotherapy and radiation — a path that Kennedy chose during his 15-month bout with the disease.

It is unclear when McCain will return to the chamber, but his friends have reported that he expects to stay involved while fighting the cancer. On Thursday morning, McCain issued a statement criticizing President Trump’s decision to end assistance to Syrian rebels battling the government of Bashar al-Assad. “The administration is playing right into the hands of Vladimir Putin,” McCain wrote with his tendency not to mince words.

After a 2008 seizure led to his brain cancer diagnosis, Kennedy made very few appearances in the Senate, trying to help monitor the debate over the Affordable Care Act from his home on Cape Cod. If McCain’s appearances are as few and far between as Kennedy’s were, it will leave a gaping hole in the Senate’s fabric.

[McCain escaped death twice as a Navy pilot and survived five years as a POW]

Learning from more senior colleagues such as Kennedy, McCain has become a force unto himself in Congress, a power center with more sway on some issues at times than whoever holds the title of Senate majority leader. There is no other senator in the rank and file who wields that much clout. The last to do so was Kennedy.

(Victoria Walker/The Washington Post)

In the minority or majority, McCain uses his identity to shape the issues, and over the past year, nowhere has that fiercely independent status been more prevalent than in challenging Trump. Through his perch as chairman of the Senate Armed Services Committee, McCain has become Trump’s most high-profile critic of his attempt to steer a new course toward relations with Russia.

The 2008 Republican presidential nominee has called for a full investigation into the president’s 2016 campaign and its ties to Russian operatives. The first sign that something might be wrong with McCain came at a Senate Intelligence Committee hearing with James B. Comey testifying. His questions to the fired FBI director were confused and befuddled, almost making it appear that McCain was defending Trump.

He wasn’t, or at least he didn’t mean to. Some wondered whether it was fatigue or something worse. This week, we learned it was worse, much worse.

In his tributes to Kennedy over the years, McCain credited his more senior colleague with teaching him how to be a great senator.

“I admired his passion for his convictions, his patience with the hard and sometimes dull work of legislating, and his uncanny sense for when differences could be bridged,” McCain told the Boston crowd in 2009.

Theirs was an unlikely pairing. As he recounted in an oral history for the Edward M. Kennedy Institute, McCain initially viewed the liberal lion as “a bit of a bully and perhaps too passionate in expression of his views.”

Kennedy was a playboy in his early years, while McCain served in the Navy and was held captive in Vietnam for 5½ years after his fighter jet was shot down.

But they both came from dynasties in which they played the role of the underperforming ne’er-do-well. Kennedy’s older brothers included war heroes, a president and an attorney general, while young Ted needed family strings just to win a Senate seat.

McCain’s grandfather and father were Navy legends, four-star admirals who helped command the Pacific fleet during World War II and the Vietnam War. John S. McCain III was the class clown at the Naval Academy, constantly in trouble.

Together, Kennedy and McCain found common cause in the Senate, and there, in many ways, they forged bigger legacies than anyone in their respective families. Combined, their service adds up to 77 years, and counting, in the chamber.

Neither could resist the presidential temptation — Kennedy in 1980, running in the Democratic primary against Jimmy Carter; McCain, falling short in 2000 to George W. Bush, then winning the 2008 GOP nomination only to lose decisively to Barack Obama.

In a twist of fate, Kennedy provided a critical symbolic launch to Obama by endorsing the first-term senator in the Democratic primary, setting him on the path to an electoral college rout.

The friendship never wavered. “During the presidential campaign, Ted never said anything about me,” McCain said.

The Kennedy-McCain bond first blossomed during arcane policy hearings of the sea power subcommittee, where they realized their shared interests often outweighed their ideological distance.

“You never had even a small doubt. . . once his word was given and a course of action decided,” McCain said in his eulogy.

They both utilized a wicked sense of humor that left everyone at ease once the laughter ended. “The nicest thing about his laughter is that it was genuine,” McCain told the EMK Institute’s oral history.

Kennedy never called McCain by his first name only, always saying, “Oh, John,” as if he had two first names. It made McCain smile.

Kennedy may have been called the liberal lion, but he had deep pragmatism that let him work with Sen. Orrin G. Hatch (R-Utah) in creating the Children’s Health Insurance Program and with McCain on the Patient’s Bill of Rights. Neither achieved what Kennedy called the “cause of my life,” what became the Affordable Care Act, but they moved the ball forward in the direction of that cause.

Kennedy challenged presidents of both parties — some Carter allies never forgave him for the 1980 primary — and he did not hesitate to challenge his own leader. He rolled over fellow Democrats who objected to his work with the Bush White House on education and prescription-drug legislation.

McCain’s clashes with his party leaders perhaps hit a crescendo in December, when he personally delivered to Comey an unverified dossier about Trump’s ties to Russia.

Two months after Kennedy’s death, McCain told his oral history interviewer that he missed him “every day,” expecting to turn the corner and see him in the Russell Senate Office Building, where they both worked.

“Oh, John,” McCain recalled Kennedy saying after any memorable Sunday news show appearance. “I saw you on Sunday, and you really gave us hell, didn’t you?”

In March 2015, McCain again trekked to Boston, for the EMK Institute grand opening, next to the JFK Library.

No one told the Phoenix resident that the event was outdoors and to prepare for a typical Boston day that went from 55 degrees and sunny to 35 with snow squalls. He later confessed that he borrowed a topcoat from one of Obama’s Secret Service agents to endure the cold, before taking the stage to pay tribute to Kennedy’s Senate career in the same way — we all hope it will be some day far in the future — McCain’s colleagues will remember him.

“I miss my friend. I miss him a lot,” McCain told the crowd, just after he finished telling the story about the time they scared those freshman senators. “I knew I would when I said six years ago that the Senate wouldn’t be the same without him. And it hasn’t been. I have no doubt that the place would be a little more productive and a lot more fun if he were there.”

Read more from Paul Kane’s archive, follow him on Twitter or subscribe to his updates on Facebook.