Top D.C. police officials said yesterday that they were stunned when their secret decision to keep apart a Ku Klux Klan group and militant anti-Klan demonstrators backfired Saturday and the demonstrators turned on police in a violent rampage through much of downtown.

"We knew there was a possibility they might get angry at being duped ," said Police Chief Maurice T. Turner, "but we did not think it would turn violent."

"We just assumed that if we avoided a confrontation between the Klan and the demonstrators, we would avoid violence," said police spokesman Lt. Hiram Brewton, "but we were wrong."

Still, Turner and Assistant Chief Marty Tapscott said in separate interviews yesterday, they are satisfied they did the right thing when they bused Klan marchers to Lafayette Square through back streets rather than allow them to march down Pennsylvania Avenue, where thousands of angry protesters were waiting.

They also maintained that once violence did erupt later near Lafayette Square, their tactic of periodically withdrawing riot-equipped officers helped to curb the violence by removing them as targets of the protesters' rage.

However, some rank-and-file officers complained privately that they were unduly restrained by their commanders and some merchants said police should have acted more forcefully.

As it was, at least a dozen officers and an undetermined number of demonstrators were injured in the two-hour melee, which apparently erupted when some demonstrators, frustrated at the absence of any Klansmen, turned to violence. Police on scooters and horses repeatedly charged rock-and-bottle-throwing mobs and fired fusillades of tear gas. Some 38 persons were arrested, and were to be arraigned today. Windows in at least 23 stores were smashed and many establishments were looted in an area bounded by 15th, 14th, H and K streets NW.

Police said yesterday that it was too soon to estimate the price tag of the disturbance, either in police and cleanup costs, or in damage to merchants. The scene of the violence was largely deserted yesterday, with a few businessmen sweeping broken glass and preparing to open again.

Meanwhile yesterday, Del. Walter E. Fauntroy (D-D.C.) called for a "coalition of conscience" among blacks and whites to "overcome the propaganda advantages" scored by both the Klan and anti-Klan protesters in Saturday's violence.

"The overtly racist Klan got what they wanted -- widespread publicity across the nation," Fauntroy said, "and white radical organizers" of the anti-Klan action "got what they wanted, too--pictures of black youths looting and throwing bricks . . . showing America that blacks are oppressed brick throwers."

He said "Trotskyist radicals" had gone through black neighborhoods in Washington with a sound truck, "inviting young black youths to go downtown and attack the Klan."

Fauntroy urged nonviolent means of improving conditions for blacks and other poor people, including support of the Congressional Black Caucus' economic recovery legislative package on Capitol Hill.

Turner acknowledged the violence Saturday was beyond anything police expected but said, "The situation would have been much worse if we had allowed the Klan march down Pennsylvania Avenue."

He said the resentment was so great among the hundreds of ultramilitant leftist protesters gathered with thousands of other demonstrators at the fringe of the proposed Klan march route that a physical confrontation seemed likely.

"That group was getting pretty worked up," Tapscott said. The possibility that it would break through police lines and attack Klan marchers, touching off chaos and violence among police and innocent demonstrators, was a major factor in a police decision to cancel the march and whisk the 30 to 35 Klan members secretly by bus from the Capitol to Lafayette Square, Tapscott said.

The Klansmen--here to protest a bill in Congress granting amnesty to millions of illegal aliens--rallied briefly in the square, then were escorted by police out of the city before the protesters knew what had happened.

Initial reaction among many demonstrators when word spread later that the Klan had abandoned its march, was one of jubilation, punctuated by cheers of victory. Others, however, felt they had been denied a long-awaited confrontation with the Klan.

Hundreds of protesters streamed up Pennsylvania Avenue toward Lafayette Square, joined by others from McPherson Square, all of them apparently thinking the Klansmen might still be in Lafayette Square.

As the vanguard of protesters began running west on H Street toward the square a block away, they were suddenly met by a solid phalanx of horse-mounted Park Police, and the mood of the crowd, encountering horsemen instead of Klansmen, grew more hostile. Rocks, bricks and bottles began flying from the crowd. The horsemen moved against the protesters and police on foot fired tear gas.

For the next two hours, skirmishing ebbed and flowed in the streets, with protesters screaming obscenities and hurling bottles, bricks and stick-mounted revolutionary banners at police. Police flailed at protesters with their nightsticks, striking many across their backs and heads.

Still other participants, mostly local young "opportunists" who had joined the fray with "criminal intent," as Turner put it, began smashing windows and looting stores. The looting, more widespread than originally reported, included stores where cameras, bicycles, clothing and jewelry were snatched.

Turner said he attempted to withdraw his officers from the streets several times but had to redeploy them to stem the looting and also to rescue isolated officers menaced by crowds.

He said the crowds consisted of two elements: the "political demonstrators" and the "opportunists," with the "opportunists" accounting for most of the arrests during the day.

"They were just hell-bent on crime," Turner said.

As for the political demonstrators, said police spokesman Brewton, "We give them permits [to march or rally] if it is not obvious they are planning violence, regardless of their politics." That is required under the U.S. Constitution, he said.

Some groups, however, did not apply for permits Saturday or were part of a coalition of groups and thus were not directly known to police. One such group, for example, was the Progressive Labor Party, a militant Communist organization that has publicly vowed to physically attack Klan and Nazi rallies. Its members and supporters have done this several times in other cities since 1978.

Scores of Progressive Labor demonstrators were on the streets Saturday, carrying their customary red revolutionary banners. Many were seen hurling rocks, bottles and banner sticks at police during the day.

Still, said Chief Turner, "there was no reason for the anti-Klan protesters to turn violent" once the Klan had left town.