The attacker refused to stop at the presidential palace's western gate before seizing a gun from one of the guards, killing two of them and being shot dead himself, presidential press secretary Emad Sidahmed told AFP.
Bashir and his ministers were not in the palace at the time of the attack, Sidahmed said.
The president, who took power in a 1989 Islamist-backed coup, has a separate residence near the military headquarters in Khartoum.
Army spokesman Colonel Al-Sawarmy Khaled Saad said the attacker, whom he described as "insane", arrived at the gate with a sword, which he used to stab one guard.
Also Read
The man then grabbed a gun, shooting the wounded guard dead and killing another before other soldiers opened fire on him, Saad said.
In a statement, Saad named the attacker as Salah Kafi Quwa, and said he was originally from the town of Kadugli in South Kordofan state, where insurgents are battling the Khartoum government.
The president's office suggested that the attacker was mentally ill in a separate statement, but gave no further details.
Witnesses near the palace said they had heard shooting coming from the palace around 12.30 pm.
A lawyer whose offices are 200 metres (yards) from the palace said the gunfire was so loud that he had ducked for cover.
"I heard shooting coming from the direction of the palace and I hid under my office table," he said, asking not to be named.
"After it stopped I saw armed soldiers at the south gate of the palace and also police vehicles arrive nearby."
"I closed my shop and tried to hide away, and the shooting continued for 15 minutes," he said.