Pope Francis said on Saturday that problems of migration would never be resolved by physical barriers but instead required social justice and correcting the world's economic imbalances.
The pontiff, starting a two-day visit to Morocco, also backed Moroccan King Mohammed VI's efforts to spread a moderate form of Islam that promotes inter-religious dialogue while rejecting any form of terrorism or 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 vowed 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 America.
"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," Pope 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.
Pope Francis, who has made the 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 are forced to leave their homes because of poverty and political upheaval.
From the airport to the city centre, Pope Francis, 82, was driven in a white popemobile on a drizzly day as the 55-year-old king rode beside him standing in a separate vehicle, a vintage black 1969 open-top Mercedes 600 Pullman. At one point, a man rushed towards the king's car but was stopped by guards as the motorcade continued along the street lined with bystanders.
After the arrival ceremony, Pope Francis and the king were visiting an institute the monarch founded in 2015 for the training of imams and male and female preachers of Islam.
"It's a very significant event, the first time that a pope is welcomed to an institute for the training of imams," said Vatican spokesman Alessandro Gisotti.
Last month Francis visited the United Arab Emirates, where he met with Sheikh Ahmed al-Tayeb, the imam of Cairo's Al-Azhar, Sunni Islam's prestigious seat of learning.
Morocco, which is nearly 100 per cent Muslim, has marketed 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.
Pope 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".
The king said learning was the only way to combat religious extremism. "To tackle radicalism, the solution is neither military no financial; that solution has but one name: education," the king said. "What all terrorists have in common is not religion, but rather ignorance of religion."