Erdogan was not in his office at the time and no one was injured by the gunfire, the aide said.
The 53-year-old man, identified as Tugrul B., was carrying a device made to look like a bomb, the official said. The suspect was being questioned and the motive for his action was not immediately known.
Private NTV television, quoting unidentified officials, said the man had credit card debts and wanted to draw attention to his plight.
Initial news reports had said police had shot and wounded a suspected of being a suicide bomber.
Copyright 2013 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.