Thousands of Hungarians protested outside parliament Friday, hours after opposition lawmakers chained themselves to barriers in a failed effort to block legislation they call a blow to democracy.

Among the lawmakers protesting was former Socialist Prime Minister Ferenc Gyurcsany, who was briefly detained along with several other opposition lawmakers.

Parliament, where the ruling center-right Fidesz party of Prime Minister Viktor Orban has a two-thirds majority, passed a financial stability law despite objections by the European Union, which could jeopardise talks about a new financing deal with international lenders.

Hungary is trying to secure the deal with the International Monetary Fund and the EU to retain access to market funding next year, but informal talks have collapsed, leading to a downgrade in Hungary's debt rating to junk by Standard and Poor's.

Parliament also passed an election law that critics say will change the electoral system in favor of Fidesz.

Andras Schiffer, head of the small LMP opposition party whose deputies chained themselves outside parliament, told a crowd of around 3,000 Orban had betrayed voters' confidence.

Viktor Orban wants to cement an economic policy that will push Hungary into default, Schiffer told the crowd gathered in below-freezing temperatures.

Teacher Erzsebet Nagy said: We thought we had to come here as we believe democracy is in jeopardy.

Former PM Gyurcsany, who headed two previous Socialist governments and is now a member of parliament, was forcibly removed from the morning protest along with the LMP lawmakers.

Police later detained several Socialist lawmakers who tried to prevent LMP activists being taken away from outside. Those detained were later released.

Orban's autocracy can no longer tolerate even peaceful opposition and protest, Gyurcsany told Reuters after he was released.

MP Gabor Scheiring told Reuters: I have come here as it's a shame for the governing majority that people have to defend parliamentary democracy with their own bodies.

A vice chairman of Fidesz said the protests were a political parody.

Police said that by chaining themselves to the barriers, protesters blocked the entry of MPs to parliament and did not obey requests to leave, and that is why police intervened.

The government's financial stability law cements a flat personal income tax, which the opposition says would tie the hands of any future administration, but the government says it would improve the economy's competitiveness in the long run.

Peter Kreko, political analyst at think tank Political Capital, said the police action was unacceptable. These pictures which show police removing opposition lawmakers, well, we see such photos in undemocratic countries.

What the government can achieve with this is that its isolation from the West can become much stronger both economically and politically.

Since it swept to power in 2010, Orban's government has tightened its grip on the media, curbed the rights of the top Constitutional Court, renationalised private pension assets and dismantled an independent budget oversight body.

The United States has urged Orban's administration to respect democratic freedoms.

EU OPPOSES TWO LAWS

Thursday Orban rejected a European Commission request to withdraw two disputed laws in a move that could derail talks with lenders about the new financial deal. Analysts say the issue could trigger a full-blown market crisis.

European Commission President Jose Manuel Barroso had asked Orban to scrap two laws, the financial stability law and one on the central bank which the European Central Bank says infringes on the central bank's independence.

The Commission said it was assessing Hungary's response.

The government said the financial stability law was key to stable budgets and debt reduction.

Parliament passed several amendments to the central bank bill Friday to bring the legislation in line with the European Central Bank's requests, but left some contentious parts in, such as the expansion of the Monetary Council.

Parliament is due to vote on the central bank bill next week.

(Reporting by Krisztina Than; Editing by Diana Abdallah and Alessandra Rizzo)