Hundreds of protesters, angered when denied a confrontation with a Ku Klux Klan group after it abandoned a planned march yesterday, turned their rage on the city -- hurling rocks and bottles at police, blocking downtown traffic and smashing store windows in an intense hit-and-run rampage that lasted two hours.

At least 12 officers were injured, as well as an undetermined number of the estimated 5,500 anti-Klan protesters, as police on horseback and scooters repeatedly charged the demonstrators in an attempt to scatter them.

Most of the violence and damage was confined to the areas surrounding Lafayette and McPherson squares.

The Sholl's New Cafeteria, on the northwest corner of Vermont Avenue and K Street NW -- where huge plate-glass windows were shattered as startled diners fled for safety -- and the Madison National Bank, across the intersection, were most heavily damaged.

Some police on foot protected themselves with large shields as they attempted to sweep the streets of demonstrators, while still other police fired round after round of tear gas.

Several times, protesters brandishing sticks menaced police officers trying to make arrests, and each time a police cruiser drove by the moving groups of protesters, it was showered with bricks, bottles and boards.

An unmarked Capitol Police car was overturned near Lafayette Square and the windows of several other cars were broken.

Windows of stores and businesses along Vermont Avenue, 14th Street and H Street downtown were smashed by shouting groups of youths who then took items including jewelry, cameras and bicycles from the displays.

Police said 38 persons were arrested. Late last night 20 persons, who were charged with felonies including assaulting a police officer, assault with a deadly weapon and burglary, still were being held in the D.C. Jail in lieu of bond. They will be arraigned Monday, authorities said.

The others arrested were issued citations and released, police said.

By mid-afternoon, when most of the protesters had scattered, the streets and sidewalks from H to K streets and 15th to 14th streets NW just north of the White House were littered with bricks, broken bottles, shattered police barricades, protest banners and other rubble.

In a late afternoon press conference, D.C. Police Chief Maurice T. Turner said of the violence: "It was blind, senseless rage, which cannot be excused or justified."

He praised his officers for limiting the violence, saying, "I don't think there was any rioting. There were isolated incidents of looting," but he added that he did not think it was orchestrated by an organized group.

"What surprised me," Turner said, "was the violence that was directed at the police department." Asked if he thought any officers overreacted, he said, "When bricks come up and hit you alongside the head, it's hard to keep your cool."

The day started peacefully with thousands of assorted anti-Klan protesters gathering along Pennsylvania and Constitution avenues where members of the Alabama-based Knights of the Ku Klux Klan planned to march from the Capitol to Lafayette Square.

Other groups in counter-protests against the Klan assembled at the Ellipse, McPherson Square and the Lincoln Memorial.

Shortly after 11 a.m., about 30 to 35 Klansmen gathered in Senate Park, a broad grassy area at Constitution and Delaware avenues NW, just north of the Capitol. The park was fenced off and anti-Klan protesters were kept at a distance.

Some of the Klansmen carried their white robes in paper bags but none donned the uniforms. Three members of a Klan "security patrol," wearing black uniforms that included black helmets with shaded visors stood protectively around the main Klan group.

Tom Robb of Arkansas, a Klan chaplain carrying a Bible, told reporters his group was protesting a bill in Congress that would grant amnesty to millions of illegal aliens who arrived here before 1977 but put controls on future immigration.

He said they also were protesting the fact that Klan Grand Wizard Don Black could not attend the rally here because of the conditions of Black's appeal bond that prevent him from leaving Louisiana. Black was convicted in 1981 of violating the federal Neutrality Act by attempting to overthrow the prime minister of the Caribbean nation of Dominica.

"The Lord will re-establish the foundation of this nation upon . . . white Christianity and western civilizaton," Robb said, when reporters asked what the general goal of the organization was.

After the discussion with reporters, Robb and the other Klan members disappeared into an underground restroom. From there, they went to a loading tunnel and boarded a bus that whisked them to Lafayette Square about a mile away.

But a lone undetected Klansman made a symbolic march from Seventh Street and Constitution Avenue to 15th Street and Pennsylvania Avenue NW without incident, according to D.C. police.

Meanwhile, the mood was peaceful among an estimated 5,000 anti-Klan protesters who had begun gathering as early as dawn along Constitution and Pennsylvania avenues near the Capitol.

Demonstration leaders, speaking from a large platform at the reflecting pool, denounced the Klan, the Reagan administration and capitalism with slogans like, "One, Two, Three, Four, Time to Finish the Civil War; Five, Six, Seven, Eight, Forward to the Workers' State."

When the demonstrators first learned that the Klan would not march past them, they began cheering, "We stopped the Klan, We stopped the Klan," and poured onto Constitution Avenue as police lifted barricades and departed.

Some protesters led by far left Progressive Labor Party organizers and the Labor/Black Mobilization to Stop the Klan, had said they wanted to have a direct confrontation with the Klan march. Now their opportunity had been taken away by the police.

Protesters began streaming northwest along Pennsylvania Avenue, many with revolutionary banners billowing in the crisp midday air. They hoped to get to Lafayette Square before the Klan rally there was completed. But police whisked the Klansmen out of the square minutes before the protesters arrived.

Across town, meanwhile, two other groups had been gathering. At the Ellipse, a crowd of about 500 people gathered at a rally sponsored by the November 29th Coalition, a Palestinian support group. They were joined by small groups of Haitians, Guatemalans and Irish Catholics.

"We are against racism in general. It's not just the Klan. Racism runs deeper in this country and the world community," said coalition spokeswoman Kathy Dillon.

Shortly before noon, the group began marching toward McPherson Square, a few blocks away, where, some organizers had said, they planned to join up with another group of demonstrators under the leadership of the All People's Congress.

About 250 people had gathered by noon for that rally, and a series of songs and speeches began as they awaited the arrival of the November 29th group. By 1 p.m., the November 29th group arrived and a small group of people drifted down 15th Street toward H Street NW.

It was there, as marchers from the enlarged McPherson group and the Capitol Hill group generally converged around Lafayette Square--which the Klan already had left--that the first confrontations with police occurred.

A vanguard of banner-carrying protesters, both black and white, pushed through a thin police line at 15th and H Streets and began running toward the square a block west.

A platoon of U.S. Park Police officers mounted on horses suddenly appeared and began forcing the crowd back down H Street. Rocks and bottles began to fly from the crowd, several of them hitting the officers and horses. Moments later, when the crowd failed to disperse, police threw the first tear gas of the day.

For the next two hours, police chased hit-and-run groups of protesters as they dashed through downtown streets, hurling rocks and debris at officers, blocking traffic and periodically smashing store windows.

While some in the crowd urged protesters to attack police and smash windows, many others begged with them to disperse and go home.

"Please stay in the park," pleaded a voice over a demonstrators public address system in McPherson Square as tear gas drifted across the square from K Street, causing demonstrators to flee, many in anger.

Some members of the crowd smashed windows at Livingston's Pawn Shop, 1423 H St. NW, snatching cameras from the display case. Others broke windows at Big Wheel Bikes, 1004 Vermont Ave. NW and took at least two 10-speed bicycles.

One youth tried to steal a moped but apparently could not get it started and left it on the sidewalk. Moments later, police arrested one of the men who had taken a bicycle and took him away in a police cruiser.

Earlier, mounted park police, charging at a gallop, drove rock-throwing protesters from Madison Place on the east side of Lafayette Square, swinging their sticks wildly and hitting many demonstrators.

It was at this time that protesters overturned an unmarked Capitol Police station wagon at Madison and H Street, while others smashed windows of a nearby government office building.

For a few minutes, demonstrators and police exchanged volleys of rocks and tear gas until the demonstrators finally dispersed north toward K Street, two blocks away. The intersection at H and Madison was strewn with bottles, bricks, horse manure and huge smears of tear-gas powder.

D.C. police officer William McAllister, who was hit on the hand by a brick, said, "I'm a five-year veteran, and this is by far the worst brawl I've seen. I knew it was bad when we heard the radios and heard the officers screaming for help."

During many of the fiercest exchanges between police and clusters of protesters, hundreds demonstrated peacefully in McPherson Square, ignoring the violence a block away.

After leading a chant, "Reagan and the Klan work hand in hand," Larry Holmes, a national coordinator for the All Peoples Congress, said, "Now they the Klan feel that the time is right because of the suffering put upon us by the Reagan administration, we're going to point a united finger toward that White House that is hiding behind the Klan."

There were other peaceful anti-Klan gatherings elsewhere in the city. At National City Christian Church on Thomas Circle, about three dozen persons heard prayers by various ministers and watched a film called "The Klan: A Legacy of Hate in America."

The service was part of the activities organized by the Coalition for Community Unity, which also scheduled free dinners at 30 area churches and worship services at city prisons.

At the Lincoln Memorial, 100 to 150 people gathered around a banner that said "Citizens United Against Hatred and Violence" and sang "We Shall Overcome." That demonstration was organized by high school teacher Nicholas F. Boke, who wanted to stage a demonstration focused primarily against the Klan, not on national politics and economics.