* Erdogan says scandal worse than coup attempts
* Pushes on with effort to tighten grip on courts
* Says probe driven by opponents of Turkish foreign policy
* Anti-terrorist police raid aid agency on Syria border
Prime Minister Tayyip Erdogan on Tuesday described a corruption investigation shaking his government as a "black stain on Turkey's democratic history" and a worse betrayal than any of the military coups of past decades.
Addressing members of his ruling AK Party in parliament, Erdogan said the corruption investigation was being driven by outside forces opposed to Turkey's assertive foreign policy and bent on damaging its economy ahead of elections this year.
Erdogan's supporters view the investigation as a plot to undermine him orchestrated by U.S.-based Turkish cleric Fethullah Gulen, a former ally whose network of followers is influential in the police and judiciary.
In an apparent bid to force the opposition's hand, Erdogan said he could drop a controversial bill to give government greater sway over the naming of judges and prosecutors if the opposition agreed instead to changes to the constitution on control of the judiciary.
The main opposition CHP, which argues the government's plans violate the constitution, said it would only negotiate if Erdogan withdrew the proposals first. A senior AK Party official said he was not optimistic of reaching a compromise.
The corruption scandal, one of the biggest challenges of Erdogan's 11-year rule, erupted on Dec. 17 with the detention of dozens of people including businessmen close to the government and three cabinet ministers' sons.
Turkey has been held up by the United States and other Western allies as an example of a working Muslim democracy since Erdogan was first elected in 2002. But a crackdown on popular protests in June and Erdogan's reaction to the corruption scandal have raised doubts about his democratic credentials.
Erdogan has purged hundreds of police officers and sought tighter control over the courts, raising alarm in Western capitals and shaking investor confidence in what was long one of the world's fastest growing economies.
"Dec. 17 is a black stain on Turkey's democratic history. It has surpassed all previous coup attempts and has been recorded as a betrayal to the state, democracy and the nation," Erdogan said to applause from his party members.
"This operation targeted our national foreign policy, our national will, our national intelligence agency," he said.
The army forced four governments from power in the second half of the 20th century but Erdogan moved soon after taking office to break its political influence, an achievement welcomed by many at home and abroad as a democratic breakthrough.
In what appeared to be part of the tit-for-tat targeting that has become a feature of the scandal, anti-terrorist police raided the offices of the Humanitarian Relief Foundation (IHH), the main agency through which Turkey channels aid to Syria, in a move the group said was a ploy to tarnish it.
The head of the police unit that raided the IHH offices was removed from his post hours later, local media said.
Turkey has maintained an open-door policy throughout the Syrian conflict, providing a lifeline to rebel-held areas by allowing humanitarian aid in, giving refugees a route out and letting the rebel Free Syrian Army organise on its soil.
But the rise of al Qaeda-linked groups such as Jabhat al-Nusra and the Islamic State of Iraq and the Levant (ISIL) in parts of northern Syria near the border has left Ankara open to accusations it is lending support to radical Islamists.
Trying to tame a judiciary he sees as under Gulen's influence, Erdogan said he could drop a draft bill which would hand the government more control over the High Council of Judges and Prosecutors (HSYK), which makes top judicial appointments, if the opposition agreed to the amendments to the constitution.
Erdogan's opponents view the draft bill as an effort by the government to stifle the corruption investigation and have said the proposed changes violate the constitution.
"We stand where we were last night ... First they have to withdraw the proposal and that would create a platform for a possible consensus," Faruk Logoglu, vice chairman of the main opposition CHP, told Reuters.
A deal could prove difficult to reach.
The constitutional amendment could involve splitting the HSYK into a separate council of judges, over which the justice minister would have direct control, and a council of prosecutors, overseen by the minister's undersecretary, a senior ruling party official said.
Members of the councils could be elected from various parties to reflect the make-up of parliament, he told Reuters.
President Abdullah Gul, seen as a more conciliatory figure than Erdogan, has discussed the issue with opposition leaders and held talks with the prime minister late on Monday at which he raised some objections to the draft, the official said.
But the official said those objections were largely technicalities which could easily be addressed, and insisted there was no question of the ruling party backing down.
"For us the current structure of the HSYK is unsustainable. We will change this through the constitution or through a law. There is no question of us taking a step back," he said.