Police cordoned off the area in front of the Justice Ministry and the suspect could be seen on the ground as a member of the bomb squad, wearing protective clothing, removed the man's shirt and then held up a tan colored cylinder with wires coming out of it. The demolitions expert successfully defused the bomb about 10 minutes later.
Television footage showed the bomber on the ground with his head moving, but he died soon afterward.
Early reports said the man tried to enter the prime minister's office but later reports said the man was trying to enter the Justice Ministry through the staff entrance and was stopped when metal detectors went off.
Security personnel tried to get the man to pass through metal detectors again and he pulled the pin on a large grenade which failed to explode, CNN-Turkey reported.
Police then tried to arrest the man. They handcuffed his hands behind his back but he managed to escape, CNN-Turk reported. The suspect ran outside the building and was shot by a plainclothes policeman after he failed to heed warning shots, the television said.
Police suspect that the man was a suicide bomber, the Anatolia news agency said. He was later identified as Muharrem Akyurt, according to Anatolia.
When asked by reporters whether he was the target of the attack, Justice Minister Cemil Cicek refused to comment.
"The event is not important and doesn't affect our duties," he said earlier.
Members of militant Kurdish, leftist and Islamic groups are active in Turkey and have carried out bombings in the past. Police officials said they suspect that the bomber was a member of a leftist group.