The European Commission says a law in Hungary that criminalises support for asylum seekers is illegal amid a battle with the country over EU migration.

Hungary has now been referred to the European Court of Justice (ECJ) for "non-compliance" with EU legislation.

Viktor Orban's government passed a law in June stating anyone "facilitating illegal immigration" could face prison.

The law was dubbed "Stop Soros" after the billionaire philanthropist Hungary accuses of supporting Muslim migrants.

On Thursday, the Commission chided Hungary over the law, which it said curtailed asylum applicants' right to turn to national, international and non-governmental organisations for help.

It said that an infringement procedure had been opened against the country because the new legislation broke EU rules, adding that a "letter of formal notice" had been issued.

The Commission has accused Hungary of failing to respect European law when it returns asylum seekers to other countries or detains them on its border with Serbia.

"The Commission considers that the indefinite detention of asylum seekers in transit zones without respecting the applicable procedural guarantees is in breach of EU rules," it said in a statement.

Last month, a report by the Council's Venice Commission leaked to the BBC raised concerns over the new Hungarian law, noting that the legislation "criminalises organisational activities which are not directly related to the materialisation of the illegal migration".

The Hungarian government argues that it is doing the rest of Europe a service by limiting the flow of what it regards as illegal migrants into the bloc.

Hungary has also said that immigration threatens its national security, but its hardline stance has been met with widespread international criticism.

Hungarian-American businessman George Soros is one of the world's most renowned, and philanthropic, financial investors.

At the height of Europe's refugee crisis, Mr Soros pledged generous backing for aid groups supporting migrants.

Why is the law controversial?
The legislation has amended eight existing laws and introduced the new crime of "facilitating illegal immigration".

Under the new law, anyone could be jailed for working for or with non-governmental organisations that are involved in helping or campaigning for asylum seekers. Human rights groups insist all they are trying to do is help people who have entered Hungary to legally apply for asylum.

The measures also tighten restrictions on asylum, so that anyone attempting to enter Hungary from a third country where they are not directly threatened with persecution cannot claim protection.

When some 400,000 people travelled through Hungary in the middle of the migrant crisis of 2015 on their way to Western Europe, Mr Orban ordered fences be put up to halt the influx.

The Commission imposed a mandatory asylum quota for every EU state in response to the crisis, but Mr Orban refused to accept Hungary's.

In 2015, 177,000 people sought asylum in Hungary but only a few hundred were accepted. Last year, the number of asylum claims fell to about 3,200.