Pope Francis told Congress on Thursday that the United States should reject hostility to immigrants and treat them humanely, directly addressing a thorny subject that is dividing the country and stirring debate in the 2016 presidential campaign.

In the first speech by a pope to a U.S. Congress, the Argentine pontiff said the United States "must not repeat the sins and the errors of the past," when dealing with immigrants.

"Building a nation calls us to recognize that we must constantly relate to others, rejecting a mindset of hostility," the 78-year-old Francis told the Republican-dominated legislature.

Related: More than 717 pilgrims die in Mecca stampede

Aversion to illegal immigrants has featured heavily in the race for the Republican presidential nomination. Front-runner Donald Trump says he would deport the 11 million undocumented immigrants if he were elected to the White House and has accused Mexico of sending rapists and other criminals across the border.

Speaking in English to lawmakers and other dignitaries packed into the House of Representatives, Francis said America should not be put off by the number of immigrants who are trying to make it their home.

"We must not be taken aback by their numbers, but rather view them as persons, seeing their faces and listening to their stories, trying to respond as best we can to their situation. To respond in a way which is always humane, just and fraternal," he said.

The pope described himself the "the son of immigrants" from Italy who settled in Argentina last century.

Several Republican presidential candidates were in the audience, including Ben Carson who caused controversy this week by saying a Muslim should not be U.S. president.

Francis addressed Congress the day after he raised other political issues such as climate change and inequality in a speech at the White House on Wednesday, the first full day of his six-day trip to the United States.