A humiliated David Gregory confirmed he was stepping down as moderator of NBC’s “Meet the Press” Thursday night and quitting NBC after an ugly showdown with network chiefs over how he was treated.

Gregory tweeted, “I leave NBC as I came — humbled and grateful. I love journalism and serving as moderator of MTP was the highest honor there is.” He added, “I have great respect for my colleagues at NBC News and wish them all well. To the viewers, I say thank you.”

Page Six exclusively revealed last month that Gregory’s time at the nation’s longest-running TV program — moderated by the beloved Tim Russert from 1991 until his death in 2008 — was up after the show slipped into third place behind CBS’s “Face the Nation” and ABC’s “This Week.” NBC top brass gave us a telling, weak denial.

We also revealed that the embattled Gregory was seen at CNN meeting with Jeff Zucker about his next move. A source told us at the time that CNN was “currently testing for a prime-time pilot that could be perfect for David.”

Chuck ToddWilliam B. Plowman, NBC

Gregory, who moderated “Meet the Press” for the past six years, will be replaced by Chuck Todd, NBC News political director and the host of MSNBC’s “Daily Rundown.”

Other sources told us Thursday night that Gregory forced a confrontation with NBC brass after continuous rumors he would be replaced by Todd. One insider said, “Gregory was pissed off. He’d had enough and told them he was out.”

NBC News president Deborah Turness has been accused of mishandling Gregory’s long and painful dethroning. Chris Wallace, the host of “Fox News Sunday,” said, “We do have a right to be treated properly and not shabbily. If you’re going to get rid of David Gregory … then they ought to just do it. This twisting in the wind is unseemly.”

Finally, Turness yesterday confirmed Todd was taking over “Meet the Press” on Sept. 7, and Gregory is “leaving the network” after 20 years. Again, tellingly, Gregory refused to do a farewell show this weekend, which will instead be moderated by Andrea Mitchell.