A man carrying an automatic weapon was detained near the Turkish prime minister's office in Istanbul on Thursday after he threw a homemade bomb at police, local media reported.
The bomb failed to explode and the man, aged around 30, was seized by security forces at the Dolmabahce Palace in Turkey's largest city, media added.
Istanbul's police chief said the assailant had served time in prison and had links to what he described as terrorist organisations, without going into further details, Dogan News Agency reported.
It was not immediately clear if Prime Minister Ahmet Davutoglu was in the palace at the time, although both he and his predecessor, current President Tayyip Erdogan, have used the office there regularly.
Kurdish insurgents, nationalist, Islamist and left wing groups have targeted security forces in Turkey in the past.