Mauritania's parliament has unanimously passed legislation making the practice of slavery punishable by up to 10 years in prison.
Many Mauritanians are born into slavery
The new law also stipulates that anyone found guilty of promoting or being an apologist for slavery could face two years in jail.
A Mauritanian anti-slavery group, SOS Slavery, welcomed the law as a victory for the people of Mauritania.
Slavery persists in parts of Mauritania even though it was banned in 1981.
A presidential decree abolished the practice, which has existed for centuries in Mauritania, but no criminal laws were passed to enforce the ban.
Human rights groups say despite official denials the practice continues and is widespread.
Boubacar Ould Messaoud, leader of SOS Slavery, said the law was very important for the country.
"We have been demanding this law for a very long time and we are very happy that the National Assembly has passed this law.
"We now have legislation which not only defends slaves, but punishes the practice of slavery. It is an important change."
SOS Slavery says there could be up to 600,000 slaves - many of them used as bonded labour - in Mauritania.
That would add up to 20% of the population although the BBC's Ed Horton says those figures are difficult to verify.
Before the new law was passed, the Anti-Slavery International group welcomed the Mauritanian government's initiative but said the proposed law was too weak.
The group urged the government to include contemporary aspects of slavery - such as forced marriage, indentured labour or debt bondage.
And the organisation said the maximum jail term should be 30 years and new laws should allow for reparation payments to the victims.