* EU concerned politics is undermining rule of law
* President unpopular but may survive Sunday impeachment
* PM says complying with EU demands (Adds PM comment in letter to Barroso)
By Andreea Birsan and Radu Marinas
BUCHAREST, July 25 (Reuters) - Romania's government has a good chance of ousting President Traian Basescu in a referendum this weekend but after pushing the European Union's patience to the limit, it will have to tread carefully as it tightens its grip on power.
Leftist Prime Minister Victor Ponta has had a stern dressing-down from the European Union, which accuses him of undermining the rule of law, intimidating judges and removing officials in its campaign against the president.
Ponta, who accuses Basescu of overstepping his powers and is asking the public to vote on whether to impeach him, said on Wednesday he was implementing EU demands and called an opposition move to boycott the vote unconstitutional.
"At this moment, we can only hope that you will also assess these anti-democratic actions initiated by President Basescu as serious threats to the same values," Ponta said in a letter to European Commission President Jose Manuel Barroso.
Ponta came to power in May after toppling a previous rightist administration with close links to Basescu in a parliamentary confidence vote. He then set about consolidating the position of his Social Liberal Union (USL).
The political squabbling in the EU's second-poorest country has largely paralysed policymaking, raised doubts over its International Monetary Fund deal and sent the currency plunging.
The USL tried to change a series of laws to its advantage and threatened to replace Constitutional Court judges and limit its powers before backing down. It also defied a court decision.
"They had a lot of pressure from the EC, EU member-states and the United States - which has certainly had an impact," said a diplomat in Bucharest.
Romania has made progress since the 1989 overthrow of communist dictator Nicolae Ceausescu and joined the EU in 2007, but has struggled to shrug off the stigma of a second-class member.
Its justice system is monitored and it is kept outside the passport-free Schengen zone. Romania gets European cash to help it catch up with other members and the EU contributes to its 5 billion-euro IMF-led deal.
That gives Brussels an wide range of levers. Diplomatic sources said officials may even have threatened, at least indirectly, to suspend Romania's voting rights in EU decisions.
"The government is facing a huge risk," said Sergiu Miscoiu of the CESPRI political think tank "So they have only very limited space for manoeuvre."
Allegations that Ponta was guilty of plagiarism in his doctoral thesis, which he denies, have added to the angry mood and distracted attention from deep structural problems.
Growth boomed before the economic crisis but horsecarts still jostle with flashy SUVs on crumbling roads and many of Romania's 19 million people still lack modern amenities like indoor plumbing.
The conservative Basescu is unpopular because of austerity policies, accusations of cronyism and a string of gaffes. Polls show some 65 percent want to impeach him but turnout could be low.
"I'm not going to vote," said Maria Benciu, 39, hurrying to work as a sales agent. "Both of them are scoundrels."
Basescu has a fighting chance as the referendum result will only be valid if turnout is more than half - and many people say they are too sick of Romania's whole political class to vote.
"When it comes to my faith in politicians, I have to say I lost it some time ago," said Adrian Mihailescu, a marketing manager.
Basescu and anti-graft experts say Ponta's rush to oust him may be linked to a string of corruption investigations, including the conviction of Adrian Nastase, a former prime minister and mentor to Ponta.
The government accuses Basescu of having undue influence over the judiciary. Prosecutors have notched up a series of convictions and the EU has demanded that it prosecute and jail senior figures to prove it is serious about corruption.
Additional reporting by Luiza Ilie, Ioana Patran and Sam Cage in Bucharest, Michael Winfrey in Prague and Justyna Pawlak in Brussels; Editing by Angus MacSwan