MADRID — Pope Leo XIV on Monday became the first pontiff to address the Spanish parliament, delivering a speech that called for a “moral renewal” in public life and respect for the dignity of migrants, the unborn and the most vulnerable.

The address to the Congress of Deputies in Madrid marked a milestone in the relationship between the Catholic Church and Spain’s secular political establishment. The Catholic Church was a pillar of Gen. Francisco Franco’s dictatorship, during which it enjoyed broad control and influence over Spanish society, but that waned after democracy took root in the 1970s. While many Spaniards still identify as Catholic, religious observance has dropped off sharply amid secularizing trends seen in other once-staunchly Christian countries.

“The moral greatness of a nation is manifested, above all, in its capacity to accompany, protect and love those lives that are most fragile,” Leo said.

Speeches by popes to foreign legislatures are rare, since they can imply recognition of a religious leader by lawmakers. Pope Francis addressed a joint session of the U.S. Congress in 2015, and Pope Benedict XVI addressed his native German Bundestag in 2011.

At the end of his speech, lawmakers from across the political spectrum gave Leo a minutes-long standing ovation with chants of “Viva el Papa!” — “Long live the pope!”

Leo’s speech came as Israel and Iran traded fire in retaliatory strikes that threatened to drag the Middle East back into a full-scale regional war. The American pope repeated his demand for dialogue to resolve disputes.

“Peace demands diplomatic courage, ethical responsibility and a vision for the future grounded in respect for the identity of every people and in the obligation of states to resolve their disputes through the peaceful means offered by international law,” he said.

He again lamented that European defense budgets were being built up, as countries move to confront the threat posed by Russia following its war in Ukraine and the Trump administration’s threats to reduce its financial and military support for the continent.

“It is therefore a cause for concern that, in various parts of the world — and in Europe as well — rearmament is once again being presented as an almost inevitable response to the fragility of the international situation,” he said.

He repeated his demand for “rigorous ethical oversight” of automated weapons systems created by artificial intelligence “so that decisions regarding life and death are never left to automated systems nor removed from the moral responsibility of the human person.”

Leo cited the 16th century Spanish intellectual tradition, known as the School of Salamanca, that gave rise to concepts of international law and inherent human rights that arose after Spain’s colonial conquests of the Americas. He praised the theologians involved in the movement who “understood that reason could not be invoked to legitimize whatever force or self-interest that seemed convenient” and that there were “moral limits of power.”

“It must be acknowledged that society and the church herself did not always live up to these insights found in their own Christian tradition,” Leo said, in a reference to the Catholic Church’s own role in the trans-Atlantic slave trade and colonial conquest.

Speaking of modern-day human traffickers, Leo called for strengthened international and multilateral efforts to prevent the human smuggling of migrants and create conditions where they can choose to stay home. But for those who do flee conflict, poverty and climate change, he called for welcome and integration.

“This gives rise to a twofold demand for social justice: to offer safe and legal pathways, a respectful welcome and real opportunities for integration; and, at the same time, to promote the right to remain in one’s own land, working to ensure that no one has to leave their home due to a lack of peace, security or decent living conditions, including economic inequalities and the effects of the climate crisis,” he said.

Spain’s Socialist-led government has bucked a general trend in Europe and the United States by defending immigration on economic and humanitarian grounds, launching a legalization push earlier this year for hundreds of thousands of immigrants living and working in the country without authorization. Prime Minister Pedro Sánchez has highlighted the benefits of legal migration to the Spanish economy with an aging workforce and low birth rate.

Leo’s visit came at a delicate time for Sánchez. His Socialist Party has been hammered by a series of corruption scandals, though none have directly implicated him, with an investigation opened last month into a former Socialist Spanish prime minister for alleged influence peddling and other crimes tied to a government airline bailout. Separate probes have touched some of Sánchez’s closest confidants, as well as his wife and brother. Sánchez’s leftist minority government has been unable to pass legislation, including a budget for the past three years.

Leo, in an apparent reference to Spain’s polarization, warned: “political pluralism should not degenerate into the constant disparagement of one’s adversary.”

Besides migration, Sánchez, who is an atheist, and the American pontiff have converged on major issues in global politics. Last month, after visiting Leo in the Vatican, Sánchez praised Leo as a “moral compass.” Sánchez has been Europe’s most outspoken voice against the U.S. and Israel’s wars in Iran, Gaza and Lebanon, with Leo decrying the strikes on Iran as “unjust.”

“Weapons may impose a temporary silence; but they can never build a genuine and lasting peace,” Leo said.

The overlap is noteworthy since the Catholic Church in Spain has traditionally been closer to the conservative Popular Party than the left, which championed social issues such as same-sex marriage, abortion rights, and euthanasia.