The Obama administration cooked up a phony story to sell Americans on the Iranian nuke deal, lying that US officials were dealing with “moderates” in the Islamic theocracy who could be trusted to keep their word, it was reported Thursday.

In a revealing article posted on the New York Times website, President Obama’s foreign-policy guru Ben Rhodes bragged about how he helped create the false narrative because the public would not have accepted the deal had it known that Iranian hard-liners were still calling the shots.

The White House line — which Rhodes says he created — was that Obama started negotiations after the supposedly moderate Hassan Rouhani was elected president in 2013.

But Obama had set his sights on working out a deal with the mad mullahs as early as 2008, and negotiations actually began when strongman Mahmoud Ahmadinejad was still president.

Rhodes, the deputy national security adviser for strategic communications, concedes in the article that the so-called moderate regime is not moderate at all.

“We’re not betting on it,” he said.

Despite having little foreign-policy experience, Rhodes, 38, a former aspiring novelist who grew up on the Upper East Side, was in charge of a massive White House “messaging” effort that fed the bogus line to journalists.

“We created an echo chamber. They were saying things that validated what we had given them to say,” he admitted in the Times interview when asked about the plethora of “experts” praising the deal in the press.

The Times article, which will appear in the paper’s Sunday magazine, notes Rhodes, who has a writing degree from NYU, was skilled as a “storyteller.”

“He is adept at constructing overarching plotlines with heroes and villains, their conflicts supported by flurries of carefully chosen adjectives, quotations and leaks from named and unnamed senior officials,” reporter David Samuels writes. “He is the master shaper and retailer of Obama’s foreign-policy narratives.”

Asked about his misleading version of the deal, Rhodes said, “In the absence of rational discourse, we are going to discourse the [expletive] out of this.

“We had test drives to know who was going to be able to carry our message effectively, and how to use outside groups like [the anti-nuke group] Ploughshares, the Iran Project and whomever else. So we knew the tactics that worked. We drove them crazy,” he said of Republicans and others who opposed the deal, including Israeli Prime Minister Benjamin Netanyahu.

Obama, the article says, misled the public with the idea that negotiations began because of the “moderate” faction’s rise in 2013.

“Today, after two years of negotiations, the United States, together with our international partners, has achieved something that decades of animosity has not,” Obama said last July when announcing the deal.

Leon Panetta, then secretary of defense, confirmed in the article that the hard-line regime, and its military arm, was still in charge.

“There was not much question that the Quds Force and the supreme leader ran that country with a strong arm, and there was not much question that this kind of opposing view could somehow gain any traction,” he said.

“I think the whole legacy that he [Obama] was working on was, ‘I’m the guy who’s going to bring these [Mideast] wars to an end, and the last goddamn thing I need is to start another war.’ ”

Without naming him, Panetta suggested Rhodes was one of several on Obama’s staff who told the president only what he wanted to hear, the article says.

“They thought their job was not to go through this open process of having people present all these different options, but to try to force the process to where they thought the president wanted to be,” he recalled. “They’d say, ‘Well, this is where we want you to come out.’ And I’d say, ‘[expletive], that’s not the way it works.’ ”

Rhodes bashed the media for not properly reporting on foreign affairs and revealed how he fed information to reporters such as Jeffrey Goldberg of The Atlantic, a respected “Beltway insider,” as the Times called him.

“All these newspapers used to have foreign bureaus,” he said.

“Now they don’t. They call us to explain to them what’s happening in Moscow and Cairo.

“Most of the outlets are reporting on world events from Washington. The average reporter we talk to is 27 years old, and their only reporting experience consists of being around political campaigns. That’s a sea change. They literally know nothing.”

Rhodes’ assistant, Ned Price, gave an example of how they would shape the news by feeding a narrative to their “compadres” in the press corps and letting it echo across social media.

“I’ll give them some color,” Price said, “and the next thing I know, lots of these guys are in the dot-com publishing space, and have huge Twitter followings, and they’ll be putting this message out on their own.”