Under the German constitution, the government can classify countries as safe if “it appears guaranteed that neither political persecution nor inhuman or degrading punishment or treatment occurs”.
“Being able to say no is also a part of helping,” Interior Minister Thomas de Maizière told lawmakers in the chamber on Friday morning.
Many migrants were coming from the Maghreb nations not because of political persecution, but “because benefits are better [in Germany] than they might be in their home country,” de Maizière went on.
De Maizière, a member of Chancellor Angela Merkel's Christian Democratic Union (CDU), has been pushing for the move since early this year.
Large groups of men of north African appearance were blamed for mass sexual assaults against women around Cologne's main train station on New Year's Eve, marking a turning point in public opinion on asylum and migration.
Earlier in 2016 the Interior Minister went on a tour of north African countries to close agreements for them to take back deported migrants whose asylum claims had been refused.
The law would still allow for asylum seekers from the region to have their cases considered if they can show “persecution which diverges from the general political situation in their homeland.”
But opposition politicians have pushed back, saying that there is still persecution in North Africa against minorities, including homosexuals.
“This is a black day for the basic right to asylum in Germany,” Left Party MP Andrej Hunko said on Friday.
“Anyone declaring Algeria, Morocco and Tunisia to be 'safe countries of origin' is justifying the persecution of homosexuals,” Axel Hochrein, spokesman for the Gay and Lesbian Federation (LSVD), said before the vote.
“In all three countries, consensual sexuality between adults of the same sex is threatened with heavy prison sentences… [voting yes would] show that the criminalization of gays and lesbians has no human rights significance to Germany,” he added.
Now the Left Party and the Greens hope to block the measure in the Bundesrat, Germany's upper house of parliament, when it goes to a vote in June.
In 2015, Germany registered 26,000 new arrivals from the Maghreb countries.
But very few have been granted the right to remain in Germany – just 0.7 percent in the first quarter of 2016.
The procedures are made more difficult because North African migrants often arrive without any identity documents.