Francis, starting a two-day visit to Morocco, also backed Moroccan King Mohammed VI's efforts to spread a form of Islam that promotes inter-religious dialogue and rejects violence in God's name.
In recent months, migration has again risen to the fore of national political debates in a number of North African and European countries and the United States.
US President Donald Trump has promised to fulfil his campaign pledge to build a wall along the border with Mexico and on Friday threatened to close the border next week if Mexico did not stop immigrants reaching the United States.
"The issue of migration will never be resolved by raising barriers, fomenting fear of others or denying assistance to those who legitimately aspire to a better life for themselves and their families," Francis said at the welcoming ceremony.
"We know too that the consolidation of true peace comes through the pursuit of social justice, which is indispensable for correcting the economic imbalances and political unrest that have always had a major role in generating conflicts and threatening the whole of humanity," he said.
Morocco has become a key departure point for African migrants trying to reach Europe after crackdowns that closed or limited routes elsewhere. Italy's anti-immigrant interior minister has closed ports to rescue ships run by charity groups.
Francis, who has made defence of migrants and refugees a key part of his preaching, said he was concerned about their "frequently grim fate" and receiving countries must acknowledge that migrants were forced to leave their homes because of poverty and political upheaval.
From the airport to the city centre, Francis, 82, was driven in a white popemobile on a drizzly day as the 55-year-old king rode beside him standing up in a separate vehicle, a vintage black 1969 open-top Mercedes 600 Pullman.
In the afternoon, the pope spoke again of migration during a visit to a Church-run shelter. He called migration "a great and deep wound that continues to afflict our world at the beginning of this 21st century. A wound that cries out to heaven."
He said migrants and refugees had rights and dignity "independent of their legal status" and that host communities should reject "all forms of discrimination and xenophobia".
Francis and the king visited an institute the monarch founded to train imams and male and female preachers of Islam.
Morocco, which is almost entirely Muslim, has promoted itself as an oasis of religious tolerance in a region torn by militancy. It has offered training to Muslim preachers from Africa and Europe on what it describes as moderate Islam.
Francis, making the first papal visit to Morocco in 34 years, praised the monarch for providing "sound training to combat all forms of extremism, which so often lead to violence and terrorism, and which, in any event, constitute an offence against religion and against God himself".