A Canadian court has overturned a national ban on brothels after a challenge by prostitutes who argued that the law forced them to risk their safety by working on the streets.

The court in Ontario dismissed bans on pimping, soliciting and running brothels in a case that could set a precedent for the country. Prostitution is not illegal in Canada, but it is heavily regulated.

The Ontario superior court upheld a challenge brought by three prostitutes, who said the ban endangered their health and forced them into unsafe working conditions.

Justice Susan Himel ruled this week that the dangers prostitutes faced on the streets far outweighed any harm caused to the public by the existence of brothels.

Himel said the laws set up to protect prostitutes actually harmed them.

The 131-page ruling said the ban violated a provision of the constitution guaranteeing "the right to life, liberty and security", and called on the Canadian parliament to regulate the sex trade rather than ban such practices.

"These laws … force prostitutes to choose between their liberty, interest and their right to security of the person," she said.

One of the women who brought the case, Terri-Jean Bedford, argued that the provisions forced sex-trade workers away from the safety of their homes to face violence on the streets. She described the judgment as "like emancipation day for sex-trade workers".

She told a press conference: "You can't imagine how happy I am today because I've been abused by the justice system for a very long time. The federal government must now take a stand and clarify what is legal and not legal between consenting adults in private."

Valerie Scott, another of the three women, said sex workers could now pick up the phone and call the police to report a client who had mistreated them.

Scott, 52, who has worked on the streets and in massage parlours, said the ruling would allow sex workers to set up unions, have health and safety standards, hire bodyguards, and pay income tax.

"We are not aliens," she said. "We are ordinary people and now we have rights.