James Dolan and Madison Square Garden have gone nuclear in their revenge against WFAN and its parent company, Entercom, The Post has learned.

In retaliation for a summer rant by WFAN host Maggie Gray, Dolan’s MSG has ordered all of its businesses across the country to shut down working with Entercom and banned Knicks and Rangers players, as well as MSG broadcasters and personnel, from appearing on the station, according to officials involved in the decision.

In Gray’s very personal rant, she called Dolan a “vile piece of trash,” among other insults and points. The Dolan takedown was brought on because Dolan, with his band, JD and the Straight Shot, released a song called, “I Should’ve Known,” perceived to be about producer Harvey Weinstein, his longtime friend, who has been accused of raping and sexually harassing dozens of women. Gray thought it was hypocritical in light of the Garden having been found liable for a hostile work environment in the Anucha Browne Sanders sexual harassment suit in 2007.

Last week, Gray apologized on-air for the rant’s personal nature, but not for its content. It was too little, too late for the Garden.

“Entercom aired a hate-filled rant directed towards MSG, its employees and its Executive Chairman in August of this year,” Kim Kerns, an MSG spokesperson, told The Post. “They chose to take no action to remedy this until the start of this season. Only after learning they would not receive special access to players and coaches did they elect to offer an insincere half-hearted apology. We wish them no ill will. However, we decline to carry on a business relationship. We will continue to afford Entercom league-mandated access only.”

Entercom offered no comment.

The Garden is not only done with Gray, but also hosts on the station who have been sympathetic to MSG. Even Mike Francesa, who has always been easy on Dolan and who has had a close relationship with Dolan’s recently retired right-hand man, Barry Watkins, is not permitted to have Garden guests on his show.

Early in his program Monday, Francesa sided with Dolan criticizing Gray, while not using her name, saying she went “too far” and was “trying to get noticed.” He also went after Watkins’ replacement at MSG, Kerns, without naming her.

“The fact that after [WFAN and Entercom] do apologize, the Garden acted that way tells me that whoever is giving Jim Dolan his PR advice now is making a grave error and really made a dumb mistake,” Francesa said. “If someone is gracious enough to give you an apology at any time, then you won. You got your apology.”

Both the Knicks and Rangers air their games on FAN’s competitor, ESPN New York 98.7 FM. The two stations have long fought over guests for the respective teams they broadcast, wanting exclusivity.

MSG owns the Garden and Radio City Music Hall, but has spread the ban on Entercom across the nation, refusing to do business with the radio company in any of its markets, including Chicago and Los Angeles. MSG owns The Chicago Theatre and The Forum in Inglewood, Calif., among other properties.

Entercom bills itself as the top radio company in the country. It has penetration in nearly all markets. It has six stations each in New York, Los Angeles and Chicago.

Last week, Gray, almost out of the blue, apologized for her Dolan comments. Sources said that wasn’t done as some quid pro quo with MSG to call off its jihad. Personal overtures from Gray to discuss the situation with MSG officials have been denied. As Kerns said in the statement, MSG was disappointed it didn’t hear from anyone from FAN following Gray’s criticism.

On CMB Monday, Gray and her co-hosts, Chris Carlin and Bart Scott, avoided the subject until a caller brought it up in the second half of their show. Gray referenced the “MeToo” movement.

“Obviously, I’m disappointed that my words got conveyed that way by the Garden, that they were characterized as hate-filled,” Gray said. “But what I’m hoping is everyone out there, everyone, just understand the context in which I went after Dolan and why I said the things that I said, the context of what’s happening now, what’s going on. It’s much bigger than sports. … Let’s not get hung up on a word or two that I may have said. Let’s keep the entire thing in context.”

On Sunday night, Gray declined to comment when reached, but a source said she was genuinely disappointed in herself that she called Dolan names, but not with the content of her rant.

“I really didn’t mean to cause the pain that I did cause,” Gray said on the air last week. “Name-calling isn’t OK.”

In August, she did call Dolan some names, lambasting him and predicting that it might cost her access to MSG.

“You are a vile piece of trash,” Gray said about the 63-year-old Dolan. “You let Isiah Thomas call this woman [Anucha Browne Sanders] the b-word so many times she sued your ass, and she won! And then what did you do? In 2015, you brought Isiah Thomas back into the building to run the Liberty of the WNBA. You are a human embodiment of an online troll. People on Twitter couldn’t even come up with something that stupid …

“I might never get back into The Garden, even with a press pass, after this, and I don’t give a crap. I’d rather not step into that building that’s owned by this hypocrite and this disgusting, disgusting human. Yeah, you should have known. You did know. I forgot for 30 seconds just how embarrassing James Dolan is. Never again. Take your stupid song and everything you stand for, and shove it up your colossal rear end. I’m done with the Knicks.”

Gray has made a bigger name for herself on CMB, even after Francesa big-footed the team and took his old afternoon drive-time spot back after his “retirement.” CMB has found more of its footing in the 1-3 p.m. slot and, although the summer ratings book is the least important one on the radio calendar, it did quite well.