These are copies of deleted tweets by @natsecgov, who has been identified as Jofi Joseph.

Inside the National Security Council, most officials aren’t allowed to use or even look at Twitter, the popular social-networking service.

But that didn’t stop some of President Obama’s top advisers from trying to identify the person responsible for @natsecwonk, an anonymous Twitter account that published a steady stream of personal and sometimes offensive attacks on White House and State Department officials.

Three weeks ago, the group hatched a plan to trick the suspected NSC staffer into revealing himself. They would intentionally plant inaccurate, but harmless, information with him to see if it would pop up as a 140-character tweet, according to a U.S. official with knowledge of the effort.

It is not clear whether the sting led directly to the unmasking last week of Jofi Joseph, 40, who was identified as the creative force behind @natsecwonk and was fired from his position on the administration’s Iran negotiations team. But the lengths to which White House officials went to find Joseph reveal how much of an embarrassment his Twitter feed had become inside the West Wing and across the street at the stately Eisenhower Executive Office Building, where Joseph worked alongside his NSC colleagues while secretly skewering them online.

“It was like they were hunting for bin Laden in a cave and he was right in the belly of the beast all along ,” said a former NSC official who worked with Joseph, marveling that he was able to keep his identity secret for over two years.

A White House national security staffer was fired over inappropriate tweets sent out under an alias. Here are a few rules that all Twitter users in politics should know. (The Washington Post)

“We talked about it from time to time in the hallways, ‘Did you see what @natsecwonk posted?’ ” said this former official, who spoke on the condition of anonymity to discuss internal operations. “He probably heard people walking around saying things about the account.”

Joseph said in a statement Wednesday that “I deeply regret violating the trust and confidence placed in me.”

“What started out as an intended parody account of DC culture developed over time into a series of inappropriate and mean-spirited comments,” the statement continued. “I bear complete responsibility for this affair and I sincerely apologize to everyone I insulted.”

White House press secretary Jay Carney confirmed Wednesday that Joseph no longer worked for the administration, but he declined to discuss specifics. Administration officials said privately that Joseph — a political appointee who served at the pleasure of the president and could be fired more easily than a civil servant — was sanctioned not just because of offensive tweets but also because he exhibited poor judgment in an office that handles sensitive national security secrets.

Although @natsecwonk did not have a large audience by Twitter standards — fewer than 1,600 followers before the account was taken offline last week — the feed was watched closely by an influential circle of foreign policy experts in Washington think tanks, on Capitol Hill, and at the NSC, the State Department and the Pentagon.

The willingness of @natsecwonk to mock and insult the administration from a clearly Democratic point of view made it a refreshingly unpredictable read in partisan Washington — at least for those who were spared Joseph’s scathing abuse. Any preening or inflation of credentials was cause for ridicule.

His first tweet, on Feb. 12, 2011, poked fun at self-styled foreign policy experts who took to television or Twitter to discuss the reversal of U.S. policy in Egypt during the Arab Spring and tout their own involvement in decision-making.

“Now that Egypt has been solved and I’m done advising the Administration, it’s time for me to get all 2010 and join Twitter! This will be fun,” the post read.

Inside the NSC, staffers are not permitted to access social-media sites such as Twitter and Facebook, because of concerns that public accounts could compromise secrets on the NSC’s computers. Staffers’ government-issued cellphones do not have Internet access, so the only way Joseph would have been able to get to Twitter during work hours would have been to use his personal cellphone in a hallway or outside the building, several former staffers said.

Joseph, who graduated as the valedictorian of his Catholic high school in Muskegon, Mich., was described by former colleagues as a smart, ambitious foreign policy aide who specialized in nuclear nonproliferation issues. He attended Georgetown University’s School of Foreign Service, where he graduated in 1994.

A Democrat, he worked on the Senate Foreign Relations Committee advising then-Chairman Joseph Biden (D-Del.) and later as the principal foreign policy adviser to Sen. Robert P. Casey Jr. (D-Pa.). Jofi Joseph’s wife, Carolyn Leddy, is a Republican staffer on the Foreign Relations Committee.

Several years ago, Joseph was promoted from a position at the State Department, where he was working on nonproliferation, to the NSC, where he joined a team of more than two dozen aides working on the administration’s policy toward Iran’s nuclear weapons ambitions.

The former NSC official said Joseph could be sarcastic and bitter, especially in regard to colleagues who were given higher-level positions that he did not think they were qualified for.

But Heather Hurlburt, a senior adviser with the National Security Network who has known Joseph since he participated in a series of foreign policy retreats she organized in 2007 and 2008, said she was “flabbergasted” to learn that he was behind @natsecwonk.

In person, she said, “he was not more bitter or snarky than anyone else. There’s a lot of that in every administration.”

His alter ego was another story, however.

From the beginning, @natsecwonk’s tweets were full of gossipy insights about the small universe of people in the Obama foreign policy world, along with profane rants and belittling comments about their physical appearance.

Targets of some of the most sophomoric posts included Hillary Rodham Clinton, Chelsea Clinton and former national security adviser Thomas E. Donilon. The feed called Obama’s staff an unprintable name and said the president can be a nasty boss.

Over the past year, Joseph singled out some of the president’s closest advisers for his most searing attacks, including White House deputy national security adviser Benjamin Rhodes and Chief of Staff Denis McDonough, who had developed close ties with Obama during his 2008 campaign for the White House.

On Aug. 12, he wrote, “Obama’s approval rating is plunging, his 2nd term agenda struggles, yet Denis McDonough is earning kudos all around #huh? #teflonskin”

Joseph sharply questioned the administration’s response to the Sept. 11, 2012, terrorist attack on a U.S. diplomatic outpost in Benghazi, Libya, which was the subject of intense Republican criticism during the final weeks of Obama’s reelection campaign. He also brutally mocked national security adviser Susan E. Rice and U.N. Ambas­sador Samantha Power. “What’s with the dominatrix-like black suit ­Susan Rice is wearing at this ­announcement?” @natsecwonk tweeted when Rice was chosen to replace Donilon on June 5.

Inside the White House and the State Department, staffers had become convinced that the Twitter feed was an inside job.

“He was so aggressive against Clinton and a lot of colleagues at State,” said the former NSC official. “I heard that at State, it was kind of a game. People were like, ‘Who the hell is doing this?’ ”

About 10 days ago, administration officials contacted the White House counsel’s office and told the president’s attorney that they had identified Joseph as the person ­responsible for the objectionable tweets. A staffer from the legal office then confronted Joseph, who confessed to being the secret author, according to a person with knowledge of the events who demanded anonymity to discuss personnel matters.

Joseph, who held a high-level security clearance, was ordered to leave the building. The Twitter feed does not appear to have included any disclosures of classified information.

“I feel badly for him,” said another former NSC official who worked closely with Joseph on nonproliferation issues. “You’ve heard that phrase, ‘You’ll never work in this town again.’ Well, he’s just thrown his career away.”

Caitlin Dewey contributed to this report.