Azerbaijan, the second-largest Shiite Muslim nation after Iran, has a tiny Catholic population - fewer than 300 Azeris are Catholics.
Several thousand foreigners make up the rest of the Catholic community, and Azeri Jews, Zoroastrians and other minorities round out Azerbaijan's religious mix.
Francis met representatives of all the main faiths as well as president Ilham Aliyev before heading back to Rome on Sunday night after a weekend visit that took him first to Georgia.
Francis celebrated Mass in the Catholic church that was built after Saint John Paul II visited Azerbaijan in 2002. After that visit, the president donated a plot of land on the outskirts of the capital, Baku, and local Muslims and Jews helped build it.
"I cannot contain my boundless joy," 61-year old parishioner Eva Agalarova said of Francis' visit. "It is both joy and happiness that the faith gives me."
Local Azeri media has not given much attention to the papal visit and many were unaware of the forthcoming Mass. But Baku's Muslim residents still welcomed Francis' visit.
"Islam is a tolerant religion and it accepts all faiths," said Aygun Mikayilova. "I will welcome the pope's visit if he is bringing a message of peace, calm and tolerance."
Aliyev, in office since succeeding his father in 2003, has firmly allied the Shiite Muslim nation with the West, helping secure its energy and security interests and offsetting Russia's influence in the strategic Caspian region.