BERLIN — German legislation designed to make life safer for sex workers, including making the use of a condom mandatory, and a stricter “no means no” law both passed their final hurdles Friday with approval from the upper house of Parliament.

“Women and men have the right to sexual self-determination,” said Manuela Schwesig, Germany’s minister for women and families. “They can say ‘no,’ and have the right for that to be treated as ‘no,” and they have the right to protection from any form of violence.”

Legislation in 2002 that legalized prostitution gave sex workers social benefits but also led to the rapid growth of unregulated brothels, leading to calls for tighter controls.

The new legislation provides for stricter regulation of such establishments, and foresees regular confidential conversations with sex workers to help ensure enforcement.

Schwesig said many men and women sex workers have been “defenseless against the power of brothel owners” but the new law will “protect them from exploitation and violence.”

The new regulations come into force on July 1, 2017.

The so-called “no means no” law aims to make it easier for victims of sex crimes to file criminal complaints by making all unwanted sexual activity illegal, including if the victim is not in a condition to give consent.

German law previously required victims to show that they physically resisted attack before charges for rape and other sexual assaults could be brought.

It goes into effect immediately after it is formally signed by the country’s president.