By Philip Pullella and Edith Honan
NAMUGONGO, Uganda (Reuters) - Pope Francis traveled to Uganda's holiest shrine on Saturday, paying tribute to 19th century Christian martyrs killed for their faith, including for protecting young boys in the royal court from abuse by the king.
Francis, on the second leg of his first African tour, said Mass for tens of thousands of people huddled on muddy hillsides surrounding the soaring modern shrine made of iron and cone-shaped to resemble a hut of the Baganda tribe.
Twenty-five Anglicans and 22 Catholic converts where killed during the persecutions, mostly by being burned to death, between 1884 and 1887 on the orders of King Buganda Mwanga II.
The most famous of the Catholic converts was Charles Lwanga, a prefect in the royal court who was in charge of the boy pages and was killed because he tried to protect the children from the sexual advances of the king.
After their conversion they tried to spread the faith to other groups. Catholics now make up about 40 percent of the population. Churches run many schools and hospitals around the country.
"They did this in dangerous times," the pope said during a Mass celebrated from a concrete island on an artificial lake on the shrine complex outside the capital Kampala.
Traditional singing and dancing gave way to a Western-style church choir as the pope walked to the altar via a gangway over the lake, which was guarded by police scuba divers in dinghies.
Uganda has been seen as a bastion of anti-gay sentiment since 2013, when it sought to toughen penalties, with some lawmakers pushing for the death penalty or life in prison for some actions involving gay sex.
The law was overturned on procedural grounds, but not before U.S. Secretary of State John Kerry compared it to anti-Semitic legislation in Nazi Germany. Other Western donors were outraged.
Gay rights activists in Uganda said before the visit that they hoped the pope would make a gesture of tolerance to homosexuals.
Failing to address the issue would be "a missed opportunity to protect LGBT persons", said activist Frank Mugisha.
Later, at a rally with young people in Kampala, the pope was visibly moved after listening to two young Ugandans whose stories were emblematic of the struggles Africa faces - Winnie Nansumba, who was born with HIV, and Emmanuel Odokonyero, who was kidnapped and forced to be a child soldier.
The pope discarded his prepared remarks and said the ability of the two to overcome their difficulties showed how much hope, persistence and prayer can transform lives.
On Sunday morning, he is due to leave for the Central African Republic, potentially the most dangerous stop on his trip.
For nearly three years, the Central African Republic has been embroiled in an inter-religious conflict that has effectively split it in two. Thousands have been killed and more than one in five have fled internally or sought refuge abroad.
(Reporting by Philip Pullella; Editing by Alison Williams)