The attacker seized one of the guards' weapons before other guards killed him, a presidential spokesman said.
He said the man appeared to be "mentally unstable". President Omar al-Bashir was not there at the time.
Mr Bashir first seized power in a coup in 1989, and announced last month he would run for office again next year.
Press secretary Emad Ahmed said the assailant did not respond to calls to stop before he was shot dead by guards.
The International Criminal Court (ICC), which Sudan does not recognise, has indicted President Bashir for genocide in the Darfur region. He denies the charges.
The African Union (AU) has backed Mr Bashir in his rejection of The Hague-based court's indictment.
It argues that as a serving head of state, he enjoys presidential immunity.