Pope John Paul II, shaking a fist at the arid mountains around this Andean town, called on Maoist guerrillas today to abandon violence and urged Peruvians to take "concrete steps" to remedy social injustices that "leave an open field" for revolution.

In a 40-minute visit to the provincial capital that has been a focal point of bloody conflict between the Sendero Luminoso (Shining Path) rebels and government forces, John Paul asked for "urgent" measures to "correct the injustices . . . the civic neglect" of the region, which he said can lead to "explosive situations, favoring violence."

The pope, nearing the end of a 12-day trip to South America and the Caribbean, used his strongest language against the Maoist rebels whose attempts to stir armed revolution in Peru have led to dozens of battles and massacres in poor Andean villages and more than 4,000 deaths nationwide since 1980.

"I implore you with pain in my heart, and at the same time with firmness and hope, to reflect on the path you have begun," he said, speaking in Spanish and addressing "the men who have put their confidence in the armed struggle."

"Violence," he said, "is not a means of construction."

The pope declared that "Christianity recognizes the noble and just fight for justice at all levels but invites its promotion through comprehension, dialogue, and generous and effective work" while "excluding solutions by roads of hatred and death."

"I ask you then, in the name of God: change course," John Paul shouted, looking up from his text to the mountain as a lock of silver hair trailed over his forehead. "There is still time."

John Paul made only one vague reference to the need for security forces "to inspire confidence in the population." This disappointed Roman Catholic human rights activists who have documented hundreds of cases of atrocities, including massacres, torture and disappearances, allegedly carried out by government forces in the area. The government of Fernando Belaunde Terry has regularly rejected charges by the church and international human rights groups of brutalities.

Quoting from a statement by Peruvian bishops on human rights but omitting its strongest language, John Paul further softened the reference by saying security forces had an "extremely delicate" mission that was sometimes "thankless and not understood."

At the same time, he advised Peruvian clergy, whom Belaunde has accused of indirectly aiding the guerrillas, to "watch out for interests and aims intended to sharpen the antagonisms."

John Paul continued his attack on pro-Marxist aspects of liberation theology, a doctrine of activism on behalf of the poor that has had strong influence in the Peruvian church. "A commitment to liberation that is not inspired in the aim of truth, justice and love without exclusions, that is not accompanied by action in favor of reconciliation and peace, is not Christian," he said.

Ayacucho, 200 miles southeast of Lima, was blacked out by rebel bomb explosions as recently as a week ago, and security was heavy around the airport parking lot, where the pope appeared. A crowd of several thousand spectators was kept 25 feet from the podium by a six-foot chain-link fence and a line of soldiers.

The pope devoted much of his address to the need for "all Peruvians of good faith to turn their gaze to the suffering of the people of Ayacucho."

"On the horizon of Peru you are presented with a task that cannot be postponed: to work with nonviolent methods to reestablish justice in human, social, economic and political relations," he said.

He also called on the international community to "apply just measures" in economic dealings with developing countries, mentioning "discrimination in commercial trade" and financial conditions on payment of foreign debts as areas for reform.

Social and economic justice were also principal themes of the pope's address earlier in the day in Cuzco, the 12,000-foot-high capital of Peru's Inca civilization.

The pope addressed the problems of rural workers and farmers, emphasizing the "extreme differences between social classes" and the need for "adequate and urgent measures" such as land reform.

He denounced the social "plagues" of official corruption and the "corrupt business" of cocaine trafficking. He said coca plants, a traditional crop of Indians in the Andes, were being used as "a sinister poison that some exploit without the slightest scruple."