By Philip Pullella

ROME (Reuters) - Pope Francis made a surprise visit on Tuesday to towns and villages devastated by an earthquake that killed nearly 300 people in central Italy in August, comforting residents who lost everything and praying together for the dead.

The Vatican, which kept the trip secret until he arrived, issued pictures showing him standing alone and praying amid the rubble of Amatrice, one of the hardest-hit towns, with its still-standing church bell tower in the distance.

Addressing distraught residents with a megaphone, he said he wanted to come earlier but he did not want "to bother anyone" and preferred to let things settle down, particularly the building of a makeshift school.

"From the first moment, I knew I wanted to come here, simply to say I am close to you. That I am close to you, nothing more. I pray for you," he said. "In this moment of sadness and pain, let's move forward while remembering our dear ones who died here under the rubble. Let us pray for them," he said.

He visited the "red zone", which covers the center of Amatrice and is closed to the public because it is still dangerous, with most of the buildings either leveled or considered too badly damaged to live in.

A parent broke down in tears in the school as he greeted the pope. Other residents stopped his car to touch his hand from the window as moved past tent cities to visit one devastated place after another, including Accumoli, Pescara del Tronto, Arquata del Tronto and San Pellegrino di Norcia.

The visit took place on the feast of the pope's namesake, St. Francis of Assisi.

He also visited a base camp for fire brigades and made a surprise stop to share a meal with residents of a home for the elderly, many of whom lost their houses in the quake.

Luca Cari, spokesman for the national fire brigades, said during the visit to Amatrice's "red zone" the pope stopped to pray with the rescue workers and thanked them.

On the plane returning from Azerbaijan on Sunday, Francis said he had been given a choice of three days when he could visit but would not reveal which one he had chosen.

He said he wanted to visit "privately, alone, as a priest, as a bishop, as pope, but alone, privately. I want to be close to the people."

The government estimates that the Aug. 24 earthquake northeast of Rome caused damage of at least 4 billion euros ($4.5 billion).

(Additional reporting by Crispian Balmer; Editing by Richard Balmforth)