An attacker with a knife has killed two soldiers guarding a gate at Sudan's presidential palace before being shot dead by other troops, the president's press secretary has said.

The sword-wielding man, described as "insane," stabbed a guard and snatched his gun to kill him before fatally firing at another, and was then shot dead himself. 

President Omar Hassan al-Bashir was not in Khartoum's Republican Palace when the attack took place on Saturday, Emad Ahmed told Reuters. Bashir was at his official residence in another part of the capital at the time of the attack, the press secretary said.

"A little while ago someone attacked soldiers who guarded one of the gates of the palace and [the soldiers] fired on him," Ahmed said.

"[He] did not respond to calls to stop and was shot dead. Two soldiers were killed during the attack by someone who seemed to be suffering from a mental illness," he said, adding that an investigation was under way.

In a statement, Army spokesman Colonel Al-Sawarmy Khaled Saad named the attacker as Salah Kafi Quwa, and said he was originally from the town of Kadugli in South Kordofan state, where rebels are battling the Khartoum government.

The 70-year-old president came to power in a 1989 coup. He announced last month he plans to run for office again next year.

Source: Agencies