KABUL, Afghanistan  The United Nations fired its No. 2 official in Afghanistan on Wednesday after the diplomat, Peter W. Galbraith, wrote a scathing letter accusing the head of the mission here of concealing election fraud that benefited the campaign of the incumbent president, Hamid Karzai.

The head of the mission, Kai Eide, angrily denied the accusation, and senior United Nations officials and diplomats said Secretary General Ban Ki-moon had decided to recall Mr. Galbraith because of irreconcilable differences with Mr. Eide, who is Norwegian.

“He reaffirms his full support for his special representative, Kai Eide,” said a terse statement attributed to Mr. Ban’s spokesman. The day before, Mr. Ban also expressed confidence in Mr. Galbraith in a news conference at the United Nations headquarters.

But the letter to Mr. Ban from Mr. Galbraith, the highest-ranking American official working for the United Nations in Afghanistan, made clear the depth of the animosity between Mr. Galbraith and Mr. Eide and illustrated the profound concerns that remain among some international observers that the presidential election was hopelessly undermined by fraud.