By Ayla Jean Yackley

ISTANBUL (Reuters) - Turkey's top court has struck down legislation that would have shut thousands of private schools, dealing a blow to President Tayyip Erdogan's efforts to curb the influence of a cleric he has accused of covertly seeking to topple him.

Prime Minister Ahmet Davutoglu questioned the timing of the decision, which came late on Monday, as he engages in talks with opposition party leaders to form a coalition government after a June 7 election.

Many of the schools are run by followers of U.S.-based Islamic cleric Fethullah Gulen, providing his Hizmet (Service) network with revenues and new recruits. The law was ushered through by Erdogan in 2014.

Erdogan accuses Gulen, whose followers wield influence in the police and judiciary, of concocting a corruption scandal in December 2013 in a bid to bring down his government.

Gulen, who lives in self-imposed exile in Pennsylvania and presides over a worldwide network of schools and businesses, denies plotting against the state.

Erdogan has made purging state institutions of "Gulenist" influence a priority, removing or reassigning thousands of prosecutors and police officers deemed loyal to the cleric.

It is unclear how strongly his battle against what he variously calls a terrorist group or a "parallel state" can now be pursued, after the ruling AK Party he founded lost its parliamentary majority for the first time in the election.

'PARALLEL STATE'

"This law came about simply because Erdogan wanted it," said Ekrem Dumanli, editor of Zaman newspaper, seen as close to the Gulen movement.

"The constitutional court's ruling is an important indicator that the bureaucracy now senses that, with the fall in support for the AKP, it can no longer continue with illegal practices just because he orders it," he said.

Shutting the university-preparatory schools would have deprived Hizmet of a chief source of financing.

The constitutional court said the legislation violated freedom of education, the Hurriyet newspaper reported.

Story continues

Davutoglu criticized the decision, arguing the court had breached its authority and that education policy must be crafted by elected officials.

"It is thought-provoking that such a ruling was made when Turkey is engaged in coalition negotiations," he said at a news conference broadcast live, and promised to pass new legislation.

The decision marks a victory for the opposition Republican People's Party (CHP), which held a first round of coalition talks with the AKP on Monday. It had appealed to the top court to overturn the legislation.

Dumanli estimated nearly a million students, mostly from poor and middle-class families, attend the centers to prepare for a competitive national university-entrance exam. Between 15 and 20 percent of the centers were affiliated with the movement.

Pro-government media have said Erdogan considers continuation of the fight against the "parallel state" a condition for any coalition deal.

Should Turkey's political parties be unable to agree a working coalition by late August, Erdogan has the right to call a snap election, widely seen as his preferred option as it may offer a chance for the AKP to regain its majority.

(Additional reporting by Gulsen Solaker, Ercan Gurses and Humeyra Pamuk; Writing by Nick Tattersall and Ayla Jean Yackley; editing by Ralph Boulton)