GDANSK, POLAND, JUNE 12 -- Riot police charged a demonstration of thousands of praying supporters of the banned Solidarity union movement tonight after Pope John Paul II emotionally endorsed the organization in a mammoth outdoor mass in this volatile Baltic port.

Defying a police deployment unprecedented in size since the end of martial law four years ago, more than 10,000 people marched beneath Solidarity banners through Gdansk following the mass in the working class neighborhood of Zaspa.

Police blocked the march at a midtown intersection and beat demonstrators with riot sticks after they sat down on the street and began to pray. Several youths, who had covered their faces with bandanas and masks, responded by throwing rocks and bottles.

At least 10 ambulances later arrived at the scene and a number of persons, including at least one policeman, were taken to hospitals.

The demonstration came despite a spontaneous plea by John Paul at the end of the mass that "no one disturb the special character of this day," which saw him embrace the Solidarity movement more directly than ever before.

Looking out over a sea of Solidarity banners, the pope gave communion to Solidarity leader Lech Walesa and his wife and drew cheers as he insisted that the 1980 Gdansk agreements that created the Solidarity union were "a task to be fulfilled."

"I pray for you every day in Rome, I pray for my motherland and for you workers," the pope said in a series of emotional, extemporaneous comments at the close of the mass. "I pray for the special heritage of Polish Solidarity."

The declaration, before a crowd of more than 750,000 persons including Solidarity activists, climaxed five days of escalating calls by the pope for political reform of Poland's communist system and respect for the nonviolent struggle of its opposition.

The campaign has underlined the extent to which the Roman Catholic Church and the government of Gen. Wojciech Jaruzelski continue to differ over Solidarity's reform program and its suppression in December 1981. Jaruzelski insisted on the pope's arrival in Warsaw Monday that the government had carried out an ambitious reform program and normalized the country since the last papal visit in 1983, when martial law was still in force.

"The pope continues to go deeper in connecting the themes raised by Solidarity -- freedom, pluralism, free association -- with the ethical principles embodied in the social doctrine of the church," said Joaquin Navarro Vals, the pope's spokesman, in a briefing for reporters today.

Authorities have reacted to the pope's tour with huge deployments of police around the cities he has visited and hundreds of detentions. Polish official sources said that police security was stepped up here last night after the pope unequivocally endorsed Solidarity during a prayer meeting in nearby Gdynia.

Today, Gdansk, a city of 400,000, was virtually under police siege. All automobile traffic was banned, roadblocks stopped even pedestrian movement in the heart of the city and miles-long convoys of armored police vehicles were parked in the city center.

Vatican officials in the pope's entourage privately expressed irritation at the stiff security measures, which prevented journalists from moving outside their hotels or a government press center through much of the day. Nine foreign journalists were detained this morning for up to two hours after seeking to visit Solidarity's monument in the center of town, where the pope prayed and laid a wreath.

Vatican officials said they were also upset that television coverage of key events was kept local rather than national.

Despite the measures, hundreds of thousands of persons with passes issued by church officials gathered from early morning at the Zaspa site, a former airport runway surrounded by huge, gray housing blocks, including the building where Walesa lives.

Virtually every apartment window in the neighborhood was decorated with posters and ribbons celebrating the pope and a sea of Solidarity banners proclaiming chapters from around the country unfurled as the pope arrived. "God save us from communism," read one standard spread at the front of the crowd. Other banners backed the opposition Freedom and Peace Movement and the Independent Students Association.

The pope spoke from a 28-foot-high altar built by shipyard workers in the shape of a sailing ship's prow, with three 114-foot-high crosses rising above it like the masts of a square-rigged schooner.

In his homily, delivered to the most excited crowd he has seen in this visit, the pope underlined the necessity for workers to have a right "to decide" in their workshops. The worker "has the right to self-management -- a manifestation of which is, among other things, independent and self-governing trade unions . . . ." The crowd responded with applause, choruses of "Long live the pope" and chants of "Solidarity, Solidarity."

After the pontiff departed by helicopter for the southern city of Czestochowa, where the Black Madonna shrine stands, a large crowd of demonstrators began to march toward the center of the city.

Soon a mile-long column was headed toward the Solidarity monument outside the Lenin Shipyards, the birthplace of the union movement. The marchers chanted slogans and called on bystanders to join them. Some did.

After a march of more than two miles, thousands of police appeared in hundreds of armored vans to block the demonstrators as they passed along a narrow street toward a major intersection. The group began chanting, "Peaceful demonstration," and "No stones," in an effort to avoid violence. When the police line failed to move, youths shouted, "Be a Pole and not Big Brother."

After the charges by riot police, buses filled with plainclothed secret policemen moved into the area. The agents could be seen patrolling the zone with sticks and beating those who failed to disperse.