Before he became an outsider politician, Donald Trump was an establishment talk-show guest, appearing on Mr. Letterman’s shows more than 30 times. I rewatched all those episodes — in the last decade there were typically two a year, with the chats lasting 10 minutes or more — and what stands out is the chemistry between host and guest, both irreverent stars who came to fame in 1980s New York. Mr. Trump was an unusually game and entertaining guest, and Mr. Letterman clearly liked and got along with him. At the same time, Mr. Trump test drove his current brand of populism to crowd-pleasing success in front of a blue-state audience, and Mr. Letterman was one of the first mainstream figures on television to regularly treat Trump as a serious political thinker, not just a joke of a rich guy (although he did that, too).

The first time Mr. Trump appeared as a guest on “Late Night With David Letterman” (the NBC precursor to “Late Show” on CBS) was in 1987, the year he published “The Art of the Deal.” Mr. Trump bemoaned our “so-called allies” ripping us off by not paying enough for our military support. And there was his now familiar gloom and doom, expressed in the harsh hyperbole of a guy complaining to his taxi driver. In a broadside against the mayor at the time, Ed Koch, he called not only the subways and schools in New York a “disgrace,” but also the zoos.

In the 1980s, “Late Night” did not have an articulated political perspective, and while its host expressed liberal leanings later in his career, back then his ideological slant was as unclear as, well, that of Mr. Trump. What they also shared was a gift for stinging insults, so perhaps it’s no surprise that Mr. Trump’s gibes found a receptive audience. Mr. Trump earned applause criticizing the city’s management, the first of several times his political attacks resonated on Mr. Letterman’s talk shows. “Listening to this stuff,” Mr. Letterman said, “it seems to me you are dying to get to some public platform to superimpose those feelings upon the American awareness.”

One decade and a few appearances later, their conversation became chummier. On “Late Show,” Mr. Letterman asked Mr. Trump about the duty of the wealthy to give back. “Could you give me an idea of something nice you’ve done for someone recently?” Mr. Letterman asked, a setup to perhaps talk about charity. Instead, Mr. Trump referred to his ex-wife Marla Maples: “I married Marla, and now I’m giving her a huge settlement.”

Say what you will about the etiquette or morality of this quip, but for the purposes of late-night comedy, it’s hard to beat. Mr. Letterman chuckled, even looking a bit jealous. “If I had said that, people would have booed me,” he said.