The numbers are in, and the message is clear: It pays to bash President Trump on late-night TV.

“The Late Show with Stephen Colbert” has scored its second straight year of dominance over “The Tonight Show Starring Jimmy Fallon,” according to Nielsen Ratings — and experts say it’s because viewers are every bit as obsessed with Trump as Colbert.

An average of 3.75 million viewers tuned in to Colbert’s “Late Show” on CBS during the 2017-18 TV year, which officially ended on Sunday, according to Nielsen Ratings. That’s 46 percent more than the 2.57 million nightly viewers Fallon averaged on NBC.

Fallon — who has been faulted by Colbert fans for his softball interviews and monologues that sidestep the daily Trump news cycle — is still on top when it comes to the 18-to-49 age group that’s coveted by advertisers.

Nevertheless, his lead looks narrow, with an average annual rating of 0.61 versus Colbert’s 0.57 for the latest 12 months, according to Nielsen. ABC’s “Jimmy Kimmel Live” logged a 0.45 rating for the year. (A full ratings point represents 1 percent of US households.)

While Colbert’s ratings didn’t start to jump in earnest until Trump’s inauguration, analysts note that Fallon’s had begun to falter months earlier in September 2016, when he famously mussed the orange coif of the then-GOP presidential nominee.

Since then, “Tonight Show’s” share of the 11:35 p.m.-12:35 a.m. ET late-night audience has plunged to 29 percent from 42 percent, according to quarterly averages provided by Nielsen. Over the same period, Colbert’s “Late Show” share has soared to 45 percent from 33 percent.

On one hand, critics blame Fallon for squandering one of the richest sources for satirists that American politics has ever produced. Variety TV critic Sonia Saraiya blasted Fallon for lacking a “point of view” with a series of softball questions for Trump (“Why should [kids] want to grow up and be president?”) ahead of the hair-mussing.

But experts note that it wasn’t until Trump’s January 2017 inauguration that Colbert’s ratings began to shift into high gear. Colbert himself got flak less than three months later, when he accused Trump of being a “c–k holster” for Vladimir Putin.

Still, Colbert’s ratings continued to climb. True, the average Colbert viewer is 61 years old, versus 56 for the Fallon audience. But if Fallon’s viral videos of celebrity karaoke contests are still a lure for younger viewers, Colbert has an edge among many college viewers, according to Eugene Secunda, a professor of media studies at NYU.

“Colbert was quicker to pick up on people’s interest in Trump’s thug-like way of doing business,” Secunda told The Post. “My students are simultaneously fascinated and disgusted to see how he behaves and how he operates in the White House.”

Fallon, meanwhile, still suffers from the perception he’s a Trump suck-up. He lamented as much in June, telling The Hollywood Reporter he was not trying “normalize” Trump by mussing his hair.

Five days later, Trump in a tweet accused Fallon of “whimpering” and advised him, “Be a man Jimmy!”