LOS ANGELES — They were fierce rivals — until President Trump turned them into allies.

Three of late-night's most durable hosts took part in a rare collaboration after President Donald Trump hurled a few verbal zingers at the wee-hours crowd at a rally Monday night in South Carolina.

Stephen Colbert, Jimmy Fallon and Conan O'Brien joined together in a sketch that — in what may be a first — served as the "cold open" to both Tuesday night's broadcast of "The Late Show" on CBS and "The Tonight Show" on NBC. O'Brien's "Conan," broadcast on TBS, is on hiatus this week.

In the bit, Colbert is spotted typing up a monologue at his computer, only to be interrupted by a video call from Fallon. "Hey, lowlife," says Fallon. "Hey, lost soul," replies Colbert. Both comics were referring to some of the epithets Trump used to insult them as well as their ABC rival, Jimmy Kimmel.

Late night hosts @StephenAtHome, @JimmyFallon and @ConanOBrien collude with each other on how to respond to the president. #LSSC pic.twitter.com/slMtGxnOhL — The Late Show (@colbertlateshow) June 26, 2018

After the pair hash out all the different names Trump used, they decide to call O'Brien. They find him shaving, and surprised to learn Trump inhabits the Oval Office. He urges them to be civil. Fallon and Colbert decide to go out to lunch at the Red Hen, the Virginia restaurant that recently asked White House Press Secretary Sarah Huckabee Sanders to leave.

The sketch shows just how much late-night has changed since Trump became President in 2017. Many of the hosts — Colbert, Kimmel, Samantha Bee, Trevor Noah — have found ratings and audience growth by poking fun at Trump in blunt terms. In some cases, their antics have spilled out on to social media or sparked backlash, such as a recent advertiser boycott of Bee's program on TBS.

Fallon has not embraced political humor as tightly, but in recent days, even he has railed against Trump. The President recently used Twitter to tell the NBC host to "be a man" after he appeared to complain in a recent Hollywood Reporter podcast that his decision to have Trump on as a guest during his campaign has offended some viewers. "As you may have heard, last night, the President of the United States went after me on Twitter," Fallon said during his monologue Monday night. "So Melania, if you're watching, I don't think your anti-bullying campaign is working."

Colbert may have had a hand in getting the idea rolling among the trio. "Colbert reached out to me this morning," O'Brien told Variety via email. "I have since had my number changed."

Representatives for "Late Show" and "Tonight" declined to add further details about how the sketch came together.

Such collaboration among TV's sundry wee-hours programs is rare. Johnny Carson never teamed up with Arsenio Hall or Pat Sajak. His successors, Jay Leno and David Letterman, viewed each other skeptically, rather than with warmth. In 2010, however, the pair surprised the world by holding forth during a promo in CBS' broadcast of Super Bowl XLIV with Oprah Winfrey. Letterman and Leno feuded for years after Letterman decamped from NBC to host a rival to "Tonight" on CBS once the Peacock chose Leno to take over for Carson on the late-night mainstay.

The current generation of late-night hosts is different. TV has many more of them and the hosts appear to adhere to an unwritten rule that calls for civility.

James Corden has appeared as a guest on Seth Meyers' NBC program, for instance, even though the two compete in the same time slot. Samantha Bee and Robin Thede have appeared on Colbert's "Late Show" and Colbert in turn has been a guest on Kimmel's ABC program. When Fallon kicked off his "Tonight" run in 2014, Colbert made an appearance in the debut show. When Colbert launched "Late Show" on CBS in 2015, Fallon was there to return the favor.