By Anthony Boadle

BRASILIA (Reuters) - President Michel Temer on Wednesday criticized a surprise move by Brazilian lawmakers, including some members of his party and even a cabinet minister, to wipe the slate clean on illegal donations they allegedly received.

As prosecutors in the widening Petrobras corruption scandal start to indict some of the 50 politicians investigated for receiving kickbacks, lawmakers anxious to avoid prosecution attempted to pass a bill to specifically criminalize off-the-books donations.

But the late-night debate in the lower chamber of Congress on Monday was a ploy: the bill's supporters argued that new laws cannot be retroactive, so past offenders would be off the hook, something legal experts said was absolutely false.

The spurious bill was blocked by lawmakers from parties whose members are not implicated in the massive graft scheme at state-run oil company Petrobras over the last two years.

Temer distanced himself from the bill sent for debate by coalition party whips, including from his Brazilian Democratic Movement Party (PMDB).

"I was surprised. I gave no guidance on this at all. Personally, I do not think it is a good idea," he told reporters in New York after speaking to foreign investors.

His minister for congressional affairs, Geddel Vieira Lima, however, said slush funds, a traditional form of under-the-table election funding, are not named in Brazil's criminal code, so a specific law covering them should be passed. That, he argued, would be a law that could not retroactively punish lawmakers who had accepted such funds.

Critics, such as Congressman Alessandro Molon, strongly refuted that, saying that laws on the books already mandate that politicians must declare all donations, and that any undeclared donations - the slush funds - are considered illegal. So the creation of a law simply naming them would not result in an amnesty for those who took such funds in the past.

Former vice-president Temer was sworn in last month as president after the removal by impeachment of his predecessor Dilma Rousseff amidst Brazil's biggest corruption scandal that has landed executives in the country's top construction firms in jail and implicated dozens of members of the once-ruling coalition.

Rousseff and her leftist Workers Party ousted from power after 13 years accuse Temer of leading a plot by politicians seeking to take over the government to avoid prosecution.

Monday's attempt to quickly pass a law that could have put dozens of politicians in the clear pointed to a political establishment scrambling to curb the sprawling Petrobras investigation dubbed "Operation Car Wash" and led by anti-corruption Judge Sergio Moro.

The president of Brazil's Senate, Renan Calheiros, a member of the PMDB and himself under investigation for graft, on Tuesday criticized the "excesses" and "exhibitionism" of federal prosecutors in the investigation.

On Tuesday, Moro put former President Luiz Inacio Lula da Silva on trial for corruption, sending a message to lawmakers under investigation that there will be no respite.

Molon, who quit Lula's party due to its involvement in corruption, said Brazilian politicians will continue to look for ways to escape prosecution.

"They'll try again. Brazilians must stay alert until the risk is totally gone," he said by telephone.

(Additional reporting by Lisandra Paraguassú; Editing by Andrew Hay)