A man shouted "traitor" and fired two shots at a prominent Turkish journalist outside a court where the journalist is on trial accused of revealing state secrets.
Can Dundar, editor-in-chief of the opposition Cumhuriyet newspaper, escaped the attack unhurt after authorities managed to subdue the gunman on Friday, but Yagiz Senkal, a journalist working for private NTV television was slightly injured in the leg.
Dundar had spoken to some journalists who were covering his trial for revealing state secrets in reports on alleged government arms smuggling to Syria. The attack occurred when he was heading towards a cafe with his wife.
Cumhuriyet's Ankara representative, Erdem Gul, who is on trial along with Dundar, told CNN-Turk television that the attacker shouted "traitor" as he fired at Dundar.
The attacker was subdued by an opposition party legislator and Dundar's wife outside the court and was quickly detained by police. Dundar's bodyguard brought the journalist to safety.
Video footage showed plain-clothed police officers forcing the man to lift his jacket to check that he had no other weapons. He was then seen lying face down on the ground.
Dogan news agency identified the attacker as 40-year-old Murat Sahin, who it said had a previous criminal record.
READ MORE: Is press freedom under attack in Turkey?
Last year, Cumhuriyet published what it said were images of Turkish lorries carrying ammunition to Syrian fighters. The paper said the images proved that Turkey was smuggling arms to rebels - a claim the government rejects.
Turkish President Recep Tayyip Erdogan and the national intelligence agency, MIT, are plaintiffs in the case which is widely seen as a test for press freedom in Turkey. The case against the two journalists was opened after Erdogan filed a criminal complaint.
"I don't know who the attacker is but I know who encouraged him and made me a target," Dundar said in a comment that appeared to be aimed at the Turkish president and others who have called for the journalists to be punished for the arms smuggling reports.
Kemal Kilicdaroglu, the leader of the main opposition party who has supported the journalists, echoed his words.
"Those who turn journalists into targets by using hate speech are responsible for the attack on Can Dundar," he said.
There was no immediate comment from Erdogan's office.
Prosecutors have recently dropped the charges of espionage and aiding a terrorist organisation levelled at Dundar and Gul. The court is deliberating whether to convict them over the charge of revealing state secrets.