The Moroccan parliament on Wednesday, after months of heated debate, adopted a law first drafted five years ago to combat violence against women.
"Thank God!" Hassima Hakkaoui, the minister of family affairs, women and solidarity, wrote on her Facebook page, after the law first drafted in 2013 was ratified by a vote of 112 for, 55 against and one abstention.
Her department said the law, for the first time in Morocco, criminalises "acts considered forms of harassment, aggression, sexual exploitation or ill treatment" of women.
Commentators on social media noted that the law finally passed on Saint Valentine's Day.
In a society divided between conservative and progressive strands, violence against women, especially in public, is often highlighted in the media and by rights groups.
It became a hot issue last August after a video was posted on the internet showing a young woman on a bus being sexually molested by a group of boys without the driver or other passengers reacting to her appeals for help.
Women's organisations said the law passed on Wednesday did not go far enough.
It "makes no mention of the problem of marital rape", pointed out a Moroccan association which campaigns for the protection of women.
More than 40 percent of women living in towns and aged between 18 and 64 who took part in a survey carried out by Morocco's High Commission for Planning said they had been "victims of an act of violence at least once".