Two security guards have been killed outside the presidential palace in Khartoum, Sudan's military spokesman said.
Sawarmy Khaled said that Saturday's attack started when a man argued with the guards at the palace because he wanted to pass through a security-cordoned area.
Mr Khaled said the man stabbed a guard with a sharp object, then seized a gun and started firing.
Mr Khaled said other guards killed the man in a firefight.
He said the man, a native of the Kordofan province, had no known political affiliation and described him as "mentally unstable."
President Omar al-Bashir was not in the palace and further security was deployed after the shooting.