Asked how he would advise American Catholics in an election in which both major candidates diverge from some Catholic teachings — the Republican nominee, Donald J. Trump, has vilified immigrants and religious minorities — Francis recommended that voters study the candidates’ concrete proposals, pray “and choose in conscience.”

Regarding his remarks a day earlier, when he criticized “gender theory,” Francis said he disapproved of schools or textbooks that “indoctrinate” the belief that gender is something a person can choose or change. But he added that the role of a good priest is to accompany someone struggling with these feelings — not to abandon or condemn the person. He also said Jesus would not turn such people away.

He noted that last year, he received a letter from a Spaniard who had undergone female-to-male gender reassignment surgery and who later married a woman. The man asked the pope if the couple could visit him at the Vatican, and Francis agreed. “I received them,” he said. “They were happy.”

Francis’ short visit, about 10 hours, to oil-rich Azerbaijan was the final stop in his bifurcated tour of the Caucasus, which began with a June visit to Armenia. He returned over the weekend to spend two days in Georgia before arriving on Sunday morning in Baku, the capital of Azerbaijan at the edge of the Caspian Sea.

In visiting the Caucasus, Francis waded into a region troubled by rivalries and conflict, but one with geopolitical importance as a historical crossroads between East and West. Georgian leaders lobbied Francis over their efforts to reclaim territory now under the control of separatist groups supported by Russia. In Armenia and Azerbaijan, he was pulled in opposite directions in their long conflict over the region of Nagorno-Karabakh.