By Ayla Jean Yackley and Melih Aslan

ISTANBUL (Reuters) - Two prominent Turkish journalists were sentenced to at least five years in jail for revealing state secrets on Friday, just hours after a gunman tried to shoot one of them outside the courthouse in Istanbul.

Can Dundar, editor-in-chief of the opposition Cumhuriyet newspaper, who was unscathed in the shooting, was given five years and 10 months. Erdem Gul, the newspaper's Ankara bureau chief, was sentenced to five years. They were acquitted of some other charges, including trying to topple the government.

The case, in which President Tayyip Erdogan was named as a complainant, has brought widespread condemnation from global rights groups and increased fears about freedom of the press in Turkey, a NATO member and EU candidate country.

Hours before the verdict was handed down, an assailant attempted to shoot Dundar. In full public view, before a courthouse, the attack marked an alarming development in a country already grappling with bombings by Kurdish insurgents and spillover of violence from neighboring Syria.

The man shouted "traitor" before firing at least two shots in quick succession. A reporter covering the trial appeared to have been wounded.

A Reuters witness said the assailant was detained by police. Before the shooting, he had approached reporters, saying he had been waiting since early morning and hoped Dundar would be found guilty. His motives and background were not immediately clear.

"We experienced two assassination attempts in two hours: one by firearms, the other by law," Dundar told reporters following the trial. "There will always be concerns that the orders of the highest office played a role in this ruling."

The two journalists are free pending appeal. The court also decided to postpone a hearing on separate charges of links to a terrorist group until the outcome of a related case.

In Washington, the U.S. State Department in a statement voiced concern about the verdicts and called on Turkish authorities to "support an independent and unfettered media, which is an essential element of any democratic, open society."

Story continues

No one was immediately available for comment at Erdogan's office after the ruling.

Dundar and Gul had faced up to life in jail on espionage and other charges for publishing footage purporting to show the state intelligence agency taking weapons into Syria in 2014.

'HEAVY PRICE'

Erdogan has acknowledged that the trucks, which were stopped by gendarmerie and police officers en route to the Syrian border in January 2014, belonged to the National Intelligence Organisation and said they were carrying aid to Turkmen battling both Syrian President Bashar al-Assad and Islamic State.

He has accused the journalists of undermining Turkey's international reputation and vowed Dundar would "pay a heavy price", raising opposition concerns about the fairness of any trial.

"We say the incident we covered was a crime, not our coverage," Dundar said. "And for that we were confronted by the president. He acted like the prosecutor of this case. He threatened us and made us targets."

Under the ruling AK Party, which was founded by Erdogan, Turkey has seized control of opposition newspapers and broadcasters and cut the satellite feed of a pro-Kurdish channel, accusing them of terrorism-related activities.

"This case isn't based on law, it's political," said Mahmut Tanal, a lawmaker from the opposition Republican People's Party.

'SYSTEM' ON TRIAL

The Committee to Protect Journalists condemned the verdict.

"What was really on trial was the Turkish criminal system, which is guilty of gross misconduct," said the New York-based group's executive director, Joel Simon, in a statement.

Journalists have been targeted in the past. Last month senior Turkish security officials were among 34 defendants put on trial accused of links to the murder of a prominent Armenian journalist, Hrant Dink, a decade ago.

Dink, who ran a newspaper serving Turkey's 60,000 Christian Armenians, was gunned down in broad daylight on a busy Istanbul street in 2007.

Gul and Dundar spent 92 days in jail, almost half of it in solitary confinement, before the constitutional court ruled in February that pre-trial detention was unfounded because the charges stemmed from their journalism.

Erdogan said he did not respect that ruling.

(Reporting by Ayla Jean Yackley; Editing by Ralph Boulton and Diane Craft)