Polish riot police used tear gas, water cannons and noise grenades today to disperse crowds of demonstrators in at least four major cities on the second anniversary of the labor agreement that gave birth to the now-suspended independent Solidarity trade union.

The Polish news agency PAP said that two demonstrators were killed Tuesday afternoon when security forces opened fire in the southwest town of Lubin near Wroclaw, Agence France-Presse reported early Wednesday.

Eyewitnesses described street battles in Warsaw, Gdansk, Wroclaw and Krakow after police moved in to break up rallies called by underground Solidarity leaders for this afternoon. Demonstrators managed to erect makeshift barricades in some places, and scattered skirmishing continued into the night. But security forces swiftly regained control in most cases by firing thousands of tear-gas grenades from mobile launchers and letting off deafening concussion grenades.

Officials said that there were smaller demonstrations in Szczecin, Przemysl, Katowice, Czestochowa and Rzeszow, although details were not available on how protesters were treated in those cities.

With the exception of Wroclaw, the turnout for the demonstrations was considerably smaller than the organizers had hoped. The authorities apparently dissuaded many Solidarity sympathizers from taking part by repeated warnings of possible bloodshed and by mounting a huge show of armed strength on the streets of Warsaw and other cities.

The day's events thus underlined the difficulties faced by the Solidarity underground in organizing mass protests under conditions of martial law. To mobilize their supporters, union leaders in hiding had to announce the demonstrations a month in advance, giving the military government more than enough time to come up with adequate countermeasures.

In the Baltic port of Gdansk, a crowd estimated at 4,000 to 5,000 gathered outside the gates of the Lenin Shipyard -- scene of the 17-day strike in August 1980 that resulted in an agreement to legalize independent trade unions for the first time in the Communist Bloc. Shipyard workers laid flowers at the base of a monument to colleagues killed during food riots 10 years earlier, sang patriotic hymns and listened to speeches by Solidarity activists.

Solidarity backers met peacefully for more than an hour, eyewitnesses said, but columns of riot police attacked when the crowd began chanting slogans demanding the release of the union's leader, Lech Walesa, and other detained officials.

Some of the most severe disturbances appeared to have taken place in the southwestern city of Wroclaw, a Solidarity stronghold, where the authorities imposed a curfew. Communications with the city were interrupted this evening, but eyewitnesses had previously reported crowds of up to 20,000 demonstrators gathering in the city center.

Elite paratroop regiments were said to have been called into the city of more than 2 million to assist the riot police.

The Associated Press reported that the government's press spokesman, Jerzy Urban, told an evening press conference: "I can assure you that before today is over, there will be quiet all over the country. This is because the people want it and also because security forces are determined to restore order."

In Washington, the State Department issued a statement saying the demonstrations "show once again that repression will not solve Poland's problems and that reconciliation among the authorities, the (Catholic) Church and Solidarity is urgently needed." Wishing the union a long life, the statement said President Reagan's policies are "aimed at advancing reconciliation in Poland through the release of the prisoners, an end to martial law" and the restoration of reconciliation talks.

The official Soviet news agency Tass said that the demonstrations were "coordinated with foreign subversive centers" and showed that antigovernment forces were not finished yet, AP said.

Political analysts here say the obvious superiority of the government forces on the streets may force a rethinking of tactics by the underground. The head of Solidarity's Warsaw chapter, Zbigniew Bujak, who is now in hiding, had argued for the demonstrations as a means of forcing the government to the negotiating table with Walesa.

A further blow to the Solidarity underground came with an official announcement of the arrest in Warsaw of one of its leading activists, Zbigniew Romaszewski. A physicist with the Polish Academy of Sciences, Romaszewski, 42, was considered the brains behind the clandestine Radio Solidarity and an advocate of radical opposition to the martial-law government.

The demonstrations did indicate, in any case, continuing unpopularity of the Communist authorities. Witnesses said passersby defiantly shouted "Gestapo, Gestapo!" at the police even though only relatively few Poles were willing to risk prison sentences and possible injury by expressing their opposition on the streets.

In Warsaw, crowds formed in only two of the four central squares designated by Solidarity for rallies. About 4,000 people gathered near the Palace of Culture, the Stalinist building shaped like a wedding cake that dominates the city skyline, despite the presence of nearly 40 truckloads of police plus jeeps and armored personnel carriers. Another 2,000 or so people gathered near Castle Square in the Old Town.

Police used loudspeakers in an attempt to disperse the crowds at both sites. "Go home, your Mr. Bujak won't be turning up, unfortunately," a policeman told Solidarity supporters near the Palace of Culture.

When some demonstrators started chanting, "We want Walesa," the police attacked in force. Shouting "Solidarity" and "Junta to Moscow" -- referring to the formal military junta led by the Communist Party chief, Gen. Wojciech Jaruzelski -- the crowds were forced into side streets away from the principal thoroughfare and then split into small groups.

In contrast to the last round of major street disturbances in Warsaw, on May 3, riot police refrained from charges with night sticks. Instead they fired round after round of tear gas, forcing the demonstrators to run from the choking stench that hung over the city center into the night.

At Nowa Huta, near the southern city of Krakow, witnesses said about 2,000 workers marched from the giant steelworks toward the town center. Fighting began after strong forces of riot police blocked the road.

In Gdansk, eyewitnesses said battles with police were continuing by nighttime in at least three separate areas and barricades were set up on several roads leading out of town.

There were no reliable reports of injuries. But, as in other cities, ambulances were seen rushing through the streets and some demonstrators were hit by tear-gas canisters.