A senior White House national security aide who was critical of the Obama administration’s “whitewash” of the attack on the Benghazi consulate has been fired for writing anti-administration messages under the pseudonym @natsecwonk on Twitter.

Jofi Joseph, who was a key member of the White House team negotiating on Iran’s nuclear weapons program, was fired after a monthslong internal investigation. A White House official confirmed Wednesday that Mr. Joseph no longer works for National Security Council but wouldn’t go into details of his termination.

Beginning in 2011, Mr. Joseph, 40, tweeted messages critical of the administration under the @natsecwonk name, sometimes insulting his bosses’ intelligence and blasting administration policies. His targets included senior presidential adviser Valerie Jarrett, former National Security Adviser Thomas E. Donilon, Deputy National Security Adviser Ben Rhodes, Secretary of State John F. Kerry and former Secretary of State Hillary Rodham Clinton.

Mr. Joseph apologized Wednesday for his actions.