* Twitter says files petitions with Turkish courts
* Ankara court upholds separate appeal against ban
* Erdogan's office says regulator has 30 days to respond
* PM has accused Twitter of undermining national security (Recasts with Twitter statement)
By Humeyra Pamuk and Orhan Coskun
ANKARA, March 26 (Reuters) - Prime Minister Tayyip Erdogan appeared on Wednesday to have succeeded in asserting a ban on the Twitter networking site in the run-up to critical local polls he fears could be influenced by what he calls fake online tapes accusing him of corruption.
An Ankara court upheld an appeal against the ban from the bar association but a source in Erdogan's office said the telecoms authority had 30 days to implement or appeal the decision. The regulator did not immediately comment.
The ruling, despite a separate court challenge by Twitter describing the blocking order as "disproportionate and illegal", would allow the ban to stay in place until after the polls, an attempt to impede widely expected further releases of tapes.
Sunday's polls have assumed huge significance as a test for Erdogan as he fights graft accusations he says were fabricated by a former ally, U.S.-based cleric Fethullah Gulen. Recent weeks have seen almost daily anonymous internet release of tapes of telephone conversations suggesting Erdogan was involved in corruption. The prime minister calls them "montages".
Reuters has not been able to verify the authenticity of the leaked recordings.
Turkey's telecoms authority (TIB) blocked access to Twitter on Friday after Erdogan said he would "root out" the network.
The move provoked public outrage and drew international condemnation, with Erdogan's critics seeing it as the latest in a series of authoritarian steps to crush a graft scandal which has grown into the biggest challenge of his 11-year rule.
Tech-savvy Turks have quickly found workarounds, with Internet analysts reporting a surge in tweets since the ban was imposed, but the issue has become a tug-of-war between Erdogan's administration and the San Francisco-based microblogging site.
Twitter said it had suspended content related to two of three court orders given as the legal basis for the ban because they violated its own rules. But it was challenging a third order to remove an account accusing an ex-minister of graft.
"With all announced bases for the access ban addressed, there are no legal grounds for the blocking of our service in Turkey," it said in an official blog posting.
"We expect the government to restore access to Twitter immediately so that its citizens can continue an open online dialogue ahead of the elections," the statement said.
Twitter's legal challenge was also expected to be delayed by Turkish court procedures.
Deputy Prime Minister Bulent Arinc, seen as a more conciliatory figure at the top of the ruling AK Party than Erdogan, urged the telecoms authority to respect the Ankara court's decision.
"We abide by the court rulings, that's what the constitution orders. We may not like them, but we abide by them. If this decision is genuine ... then what TIB needs to do after this is obvious," Arinc told reporters in Hatay in televised comments.
"NATIONAL SECURITY THREAT"
Erdogan on Tuesday accused Twitter of "threatening national security" and has repeatedly defended the ban during rallies in the run-up to the municipal elections on Sunday, his party's first test at the ballot box since the corruption scandal erupted in December and since street protests last summer.
"Our problem is not Twitter itself but its approach ... The court ruling was conveyed to Twitter. It does not listen to it," Erdogan said in a TV interview late on Tuesday about the original decision to block access.
"You are threatening the national security of my country," he said in a voice strained by weeks of campaign rallies.
The controversy over the ban has added to an already febrile atmosphere ahead of Sunday's elections, with some rival candidates even warning of armed provocateurs and possible assassination attempts during the polls.
Interior Minister Efkan Ala called on candidates to behave responsibly, saying during a visit to the eastern city of Ezurum that "every measure" had been taken to secure the polls.
His AK Party is expected to continue to dominate the electoral map after the election and is aiming for around the 40 percent share of the vote it achieved at the last local polls in 2009, although close races are expected in Ankara and Istanbul.
Turkish assets firmed on Wednesday, pricing in expectations that a solid showing by the AK Party would ease months of political uncertainty in the country.
Telecoms regulators have said the Twitter blockage was based on four court orders and was imposed after complaints from citizens that the microblogging site was violating privacy.
Erdogan's declaration last week that he would root out Twitter, and the subsequent attempt to block it in Turkey, triggered denunciations from European officials and the U.S. government, which spoke of "21st century book burning".
(Additional reporting by Jonny Hogg, Gulsen Solaker and Ozge Ozbilgin; Writing by Nick Tattersall; Editing by Ralph Boulton)
Our Standards: The Thomson Reuters Trust Principles.