Emergency legislation to ban the possession of certain drugs has been passed by the Dáil after possession of ecstasy, magic mushrooms and other new psychoactive drugs was made temporarily legal.

Minister for Health Leo Varadkar brought the legislation to the Dáil after the Court of Criminal Appeal ruled that a law banning more than 100 drugs was unconstitutional.

The Misuse of Drugs (Amendment) Bill 2015 was widely supported during a two-hour debate this evening.

It will now go to the Seanad tomorrow before being sent to the President to sign.

Mr Varadkar said he will ask the president to sign it as soon as possible.

He said if new drugs appear new legislation will be needed to add them to the banned list.

Possession of ecstasy, magic mushrooms, so called head shop drugs and other new psychoactive drugs is currently legal.

Earlier, Mr Varadkar warned anyone tempted to take advantage of the temporary decriminalisation to think about their health.

"They all have very significant health risks that outweigh any perceived recreational benefits," he said.

"We had no way of knowing what the court would decide today, but we prepared for this possibility," he said.

The Government was forced to act after a decision by the Court of Appeal on a challenge to the Misuse of Drugs Act 1977.

The case was brought by a man prosecuted for possession of methylethcathinone in 2012.

He denies criminal charges of supplying the substance and argued the regulations were unconstitutional.

The substance also known as 4-mec or snow blow is one of around 100 brought under a blanket ban in Ireland four years ago, which forced head shops around the country out of business overnight.

The three-judge court unanimously agreed a regulation making the possession of methylethcathinone illegal was invalid, as it was unconstitutional.

Because of the way the laws are drawn up, the ruling had the knock-on effect of temporarily legalising the possession of other drugs in the same category.

The Government is considering an appeal on the ruling.

It has also warned that sale and supply of the affected drugs remains an offence.

The outcome of the case does not affect existing laws on other traditional drugs like heroin, cocaine or cannabis.

Dozens of drugs-related convictions will be open to challenge after the 30-page ruling was handed down by the court, it is expected.

Mr Varadkar said emergency legislation, expected to be enacted by tomorrow, will re-instate "the status quo" and re-control all drugs that were controlled before the judgment.

In a statement, the Department of Health said there was always a degree of uncertainty about the outcome of court cases.

"The outcome of this case does not affect existing laws regarding the supply, possession or sale of older drugs such as heroin, cocaine or cannabis," it added.

"It does affect the possession of certain newer psychoactive substances which have been added to the Misuse of Drugs Act 1977 by successive governments.

"However, we are advised that sale and supply of psychoactive substances remains an offence under existing legislation."

Because of previous challenges to the laws, the Government had prepared emergency legislation.

"It is now important from both a public health and criminal justice perspective that the legislation be enacted as soon as possible," a department spokesman added.