Tens of thousands of protesters boycotted official May Day ceremonies today and staged counterdemonstrations in at least 20 Polish cities. Police responded in several cities with water cannons, tear-gas grenades and assaults.

Unfurling illegal Solidarity union banners in defiance of warnings by Communist authorities, demonstrators massed, sometimes within a few blocks of the official parades. They chanted the names of former union leaders and shouted slogans appealing for the release of political prisoners and the return of independent unions.

Protesters used Catholic Church masses as a rallying point and converged on centrally located churches in Warsaw, Gdansk and Nowa Huta, an industrial suburb of Krakow, the scenes of the biggest demonstrations.

Police here clashed with the marchers at several points, and armored vehicles and mounted police were called in to help control the protest. In Gdansk, police used water cannons and tear gas to disperse the marchers as they moved through town toward the home of Lech Walesa, the leader of the outlawed Solidarity union. Walesa did not join in the marches.

On the surface, the demonstrators were protesting the government's authority to mandate how this traditional workers' holiday should be celebrated. At its root, however, the struggle was over who really speaks for Polish workers.

Both the government and the opposition claimed victory. A Polish television commentator, citing figures that put the number of demonstrators nationwide at 40,000 and the number of those who marched in the official ceremonies at 6.5 million, interpreted the results as a referendum.

"The voting that took place on the streets," he said, "showed an overwhelming predominance of patriotism motivated by reason."

But Walesa, who stayed in his apartment in Gdansk for most of the day, said the unofficial rallies had "gone well."

Estimates by western correspondents placed the number of demonstrators in Warsaw and Gdansk combined at more than 40,000. Western diplomats noted that participation in the official parades was mandatory for many schoolchildren and others.

Polish leader Wojciech Jaruzelski told a gathering at the start of the official parade here that "counterrevolution" in Poland "is less likely to succeed today" than in 1981 when Solidarity was at its peak or the mid-1940s when the Polish Communist state was founded. He was speaking out of earshot of the melee that was taking place in the capital's Old Town.

"Although there are still attempts to sow chaos," Jaruzelski said in a brief address that was televised nationally, "they constitute today only a pitiful margin without any chance for success."

He cautioned against further protests and held out the prospect, although still indefinite, of a final lifting of martial law. "If in the coming days and months," he said, "there are no disturbances and peace is consolidated, a realistic possibility will emerge for the lifting of martial law and the taking up of follow-up actions and moves."

In Warsaw, an estimated 5,000 to 10,000 picked their way through police identification checks to reach St. John's Cathedral in the city's reconstructed Old Town. Blue and green militia vans, water cannons and armored vehicles encircled the area, and phalanxes of blue-jacketed riot police wearing helmuts and toting submachine guns patrolled the narrow streets there.

Suddenly, just before the 10 a.m. mass, people in the crowd in front of the cathedral pulled out Solidarity banners and flags from their purses and pockets. Chanting the word solidarity and the names of Walesa and other union leaders, people raised their arms in victory salutes. They shouted "Release prisoners," "We want the truth," "This is our holiday" and "Here is Poland."

After 30 minutes, during which police barked warnings to disperse over a bullhorn, militiamen carrying plastic shields and swinging long white sticks surged forward. A water cannon opened up, pushing people back farther into the Old Town where they were buffeted by other groups of police and eventually forced out onto open ground by the Vistula River.

There, joined by fresh arrivals, the crowd swelled to an estimated 10,000 to 20,000 people. They formed again beneath Solidarity banners but soon dispersed when a convoy of armored vehicles approached from one end and mounted police moved in from another side.

As scattered clashes continued throughout the afternoon, police managed--using a minimum of brutality despite some instances of serious beating of demonstrators--to prevent a large march of people from coalescing as happened last year.

In stark contrast with the spontaneity and energy of the unofficial demonstrations, the official parade meandered along its two-mile course through central Warsaw. The silence of the procession was eerie, broken only by a loudspeaker announcing passing groups and by an occasional band. Spectators were sparse along the route and, in some spots, nonexistent.

In Gdansk, meanwhile, a large red and white national flag with a Solidarity inscription was spotted hoisted on one of the towers above the central train station. A crowd estimated at between 15,000 and 40,000 assembled around the station after a mass at St. Brygida's Church near the Lenin Shipyard where Solidarity was founded.

Police were reported to have used tear gas and water cannons to disperse the group as it tried to move through the town toward the outlying housing district where Walesa lives. A group of between 500 and 2,000 people that had gathered outside Walesa's apartment also was broken up.

Commenting on the rallies, Walesa said by phone: "We stand no chance against tanks, but everything has gone well. The appeal has drawn a response."

Walesa left his apartment briefly at noon to attend mass. A Solidarity flag hung from his balcony, placed there, he said, by a union supporter.

Polish television showed film of young demonstrators hurling stones at police in Nowa Huta and Wroclaw, the Los Angeles Times reported. Other unauthorized demonstrations were officially reported in Poznan, Krakow, Szczecin, Bydgoszcz, Gdynia and Lodz. The official media did not name the other 10 cities and towns in which it said pro-Solidarity rallies took place.

The marches today, which were initiated by the underground Solidarity leadership, were the first major show of opposition since the suspension of martial law in December. They were also the largest, most widespread series of demonstrations since fierce street battles Aug. 31, the second anniversary of the signing of the worker-government agreements that gave rise to Solidarity.

The demonstrations were intended to be the last major display of public disaffection with Jaruzelski's government before the visit of Pope John Paul II in June. Polish authorities have warned that a new wave of social unrest could force cancellation of the second pilgrimage by the pope to his homeland, an event eagerly awaited by this largely Roman Catholic nation.

Underground leaders in Warsaw issued a brief bulletin urging a quiet protest Tuesday, the anniversary of the signing of the first Polish constitution and a day marked last year by angry street fighting. The bulletin advised workers this year to go to work wearing badges in red and white--Poland's national colors--and to observe a moment of silence at noon.

The pro-Solidarity crowds gathered today despite a recent intense propaganda effort by the government that accused the underground leaders of trying to stir unrest and provoke confrontation just to keep their own names in the news and to serve the interests of western powers hostile to Poland, particularly the United States.

Authorities apparently went so far as to fake a broadcast Friday night of the clandestine Radio Solidarity announcing the counterdemonstrations had been called off. But Warsaw underground leader Zbigniew Bujak issued a fresh note confirming that the unofficial rallies were still planned.