Pope John Paul II issued a departing appeal for social justice and nonviolence today before more than 1 million in Lima's largest slum district on the final day of a strenuous 12-day visit to Latin America.

Extending his arms to the crowd of mostly poor families on a sandy lot of the sprawling Villa El Salvador, John Paul called for "urgent" action by authorities to "correct the disequilibrium and disproportions of the distribution of goods."

"For the good of Peru, bread cannot be lacking in the shantytowns," the pope shouted in a rare departure from his prepared text. "You are hungry for God. And you are hungry for bread. Let the hunger for God remain and the hunger for bread be resolved."

The ceremony was held in a slum of some 300,000 people where unemployment is about 70 percent and 40 percent of homes are shacks of wood and reed mats, according to church officials. Residents of the district, where church organization has been strong since the first homes were built illegally on occupied land in 1971, spent weeks preparing for today's event and many spent the night in vigil at the meeting site.

Clearly inspired by the crowd, the pope reaffirmed the church's commitment to "effective reforms," stressing that "every unjust situation has to be denounced and corrected."

Returning to the strongest theme of his five-day visit to Peru, he added that "the solution is not a road that leads to privations of liberty, oppression of spirits, violence and totalitarianism."

The pope also called on his audience to "fight against everything that lowers your moral situation." In addition to alcoholism, drugs and prostitution, he mentioned "the macho mentality that degrades and exploits women."

The morning appearance followed a night of bombings and blackout in Lima shortly after the pontiff's return from a trip to the interior. During the blackouts, flares forming a huge hammer and sickle were ignited on several hillsides overlooking the city, and police reported armed attacks on two banks.

The bombing attacks, which were blamed here on the Maoist Shining Path insurgent group, came a day after John Paul had traveled to the Indian provincial capital of Ayacucho and appealed to the group to abandon violence. Today, he made no direct reference to the incident before departing at midmorning.

The pope stopped at midday in the eastern Peruvian jungle city of Iquitos and delivered a homily stressing the rights of indigenous tribes while urging them to accept Catholicism.

"The pope feels profound affection for you precisely because for a long time you have been the most forgotten," he said, noting that about 250,000 from 60 ethnic groups are among the 2 million residents of the Peruvian Amazon region.

The pope then made a seven-hour stop in Trinidad and Tobago, where he praised the island nation's multiracial harmony. Shortly before midnight, the pontiff left for Rome.

Church officials here said that John Paul has used his tour, which also included Venezuela and Ecuador, to reassert his personal authority over a Latin American church that some conservatives say has drifted too far from the doctrines of Rome.

While adopting few new positions in his 45 statements during the trip, the pope strongly and sometimes stridently reaffirmed a mixed message: support for the Latin American clergy's commitment to correcting social injustice, but also admonition against its perceived excesses.

Four times on the trip, John Paul spoke on behalf of the rights of workers, asserting the priority of labor over capital and declaring in Ciudad Guyana, Venezuela, that individuals must not become "the slave of the machine."

The pope also visited shantytowns in several cities and told poor peasants and farmers in Peru and Ecuador that the church defended land reform and an end to rural injustice.

While these statements pleased liberals, John Paul appeared even stronger in his denunciation of violent, Marxist ideology and the more radical precepts of liberation theology, the doctrine developed in Latin America that calls for the commitment of the church to fight social injustice.

In Peru, where the church is divided among proponents of liberation theology, centrists and conservatives, virtually every statement of the pope warned against "anti-Christian practices," "the subordination of the gospel to political and sociological categories" or the need for priests to obey the teachings of Rome.

Several warnings clearly ran against the thinking of liberation theologians like the Rev. Gustavo Gutierrez, the Peruvian who has defended the use of Marxism and other sociological methods by the church in analyzing social realities.

Gutierrez's followers here have chosen to focus on the pope's advocacy of social reform, and maintain that his criticisms have not been directed at them. However, several church officials said they believe the pope's statements may encourage church conservatives who have worked to suppress the liberation movement.

The Peruvian bishop of Arequipa, Fernando Vargas, recently sponsored a conference on a new "theology of reconciliation" that he said was meant as an alternative to liberation theology and was based on John Paul's position.