2/10/2017 9:44 AM PST

Nick Cannon Nearly Fired from 'AGT', Cooler Heads Prevail

EXCLUSIVE

Nick Cannon pissed off some NBC execs with a joke he made during a stand-up comedy special -- and it nearly cost him his job on "America's Got Talent" ... TMZ has learned.

While Nick was recording the special more than a month ago, he joked with the audience that NBC was making him lose his "black card" -- strongly insinuating the network wanted him to show less swagger on 'AGT.'

Sources familiar with the situation tell us NBC execs got wind of it when Nick was promoting the special on "The Howard Stern Show" ... and thought he was disparaging the network -- a violation of his contract. We're told his deal has a clause that bars him from talking about the network without approval.

There were serious discussions about axing him for breach of contract, or simply because ... if he's so miserable, why not just let him go?

Ultimately, the execs decided Nick had simply made a passing comment. We're told they like him and didn't want to blow the relationship. He'll be shooting 'AGT' next month.

As for the comedy special, it airs Friday night on Showtime and we're told the "black card" comment is in it.