The parliament of Morocco has unanimously amended an article of the penal code that allowed rapists of underage girls to avoid prosecution by marrying their victims.
The move follows intensive lobbying by activists for better protection of young rape victims. The amendment has been welcomed by rights groups.
Article 475 of the penal code generated unprecedented public criticism.
It was first proposed by Morocco's Islamist-led government a year ago.
But the issue came to public prominence in 2012 when 16-year-old Amina Filali killed herself after being forced to marry her rapist.
She accused Moustapha Fellak, who at the time was about 25, of physical abuse after they married, which he denies. After seven months of marriage, Ms Filali swallowed rat poison.
The case shocked many people in Morocco, received extensive media coverage and sparked protests in the capital Rabat and other cities.
Article 475 provides for a prison term of one to five years for anyone who "abducts or deceives" a minor "without violence, threat or fraud, or attempts to do so".
But the second clause of the article specifies that when the victim marries the perpetrator, "he can no longer be prosecuted except by persons empowered to demand the annulment of the marriage and then only after the annulment has been proclaimed". This effectively prevents prosecutors from independently pursuing rape charges.
In conservative rural parts of Morocco, an unmarried girl or woman who has lost her virginity - even through rape - is considered to have dishonoured her family and no longer suitable for marriage. Some families believe that marrying the rapist addresses these problems.
While welcoming the move, rights groups say that much still needs to be done to promote gender equality, protect women and outlaw child marriage in the North African country.
"It's a very important step. But it's not enough," Fatima Maghnaoui, who heads a group supporting women victims of violence, told the AFP news agency.
"We are campaigning for a complete overhaul of the penal code for women."