Diplomatic offices on Wisconsin Avenue representing the Iranian regime of Ayatollah Ruhollah Khomeini were briefly taken over and ransacked yesterday by 24 anti-khomeini protesters in an incident that ended with the shooting of one demonstrator and a melee in which two other persons were injured.

Police said the demonstrator was shot by one of five persons the protesters had held hostage on the second floor of 2139 Wisconsin Ave. NW, which houses the Iranian Interests Section of the Algerian Embassy here.

In the melee that followed the shooting, another of the demonstrators was trampled and the alleged gunman was beaten and seriously injured before police, who had been leading the demonstrators from the offices, could quell the outbreak.

The takeover brought squads of helmeted police into the area, on Georgetown's northern edge, to surround the building. Officers carrying rifles and tear gas raced past bewildered pedestrians, and for blocks around rush hour traffic was plunged into chaos.

All 24 demonstrators were arrested and charged with kidnaping and destruction of property of a foreign government, while the alleged gunman was charged with assault with a deadly, police said. The injured persons were taken to local hospitals where they were listed in stable condition.

Late yesterday afternoon, an Iranian student who identified himself only as Husien, said the demonstrators are supporters of the Peoples' Mujaheddin Organization of Iran. That is the same group that claimed responsibility for the June 28 bombing of the Majlis, the Iranian parliament, in which 71 people were killed, including several prominent Iranina leaders.

Husien said the protesters took over the office to "expose torture" by the Khomeini government. For the last few weeks, the Mujaheddin group has held demonstrations outside the Iranina Interests Section office, according to police, but did not enter the building.

The protesters took over the office at 8:30 a.m. and during the 45 minutes they held control they spray-painted slogans on walls, tied up two security guards and displayed anti-Khomeini banners from the office's windows.

"There was a lot of confusion as to what was developing," said Deputy Police Chief John C. Conner, head of the special operations division.

The demonstrators, according to law enforcement sources, had made their way up the back stairwell of the building through a door that had been left ajar with tape. The protesters swept through the second floor offices, tying up at least five persons, including the two security guards, the sources said.

The demonstrators sprayed the offices with red and black paint and burned at least one picture of Khomeini.

When the first police officers and uniformed Secret Service officers arrived, the demonstrators were chanting slogans and displaying banners from the windows.

The officers went to the second floor, but they found it locked. They then talked with the demonstrators through the door and they told the officers that they were not armed.

For 20 minutes, the officers negotiated with the demonstrators, who refused to unlock the door or release the hostages.

At one point, the demonstrators asked that they be allowed to voice their concerns to representatives of the news media before surrendering to police.

But police refused that request. The demonstrators finally agreed to come out of the office with their hands held above their heads.

"They were coming out with their hands held over thir head when a shotg was fired," said Police Capt. Kenneth L. Hutson, who was at the scene.

Bedlam erupted and police rushed into the office. They grabbed the gunman, who sources said continued to hold the gun despite the police officers' orders to drop the weapon.

One demonstrator fell during the melee and was trampled, police said. The wounded demonstrator was shot once in the back.

Both the gunman and the demonstrator who was shot were refusing to give their names as of late yesterday. The gunman was listed in critical, but stable condition at Sibley Hospital. The demonstrator was in stable condition at Georgetown University Hospital.

The demonstrator who was trampled, identified as Mahmod Kupai, 19, of Los Angeles, suffered bruises and was listed in fair condition at Georgetown University Hospital.

As police led the group of protesters, all of them young men, toward vans, the Iranians yelled such anti-Khomeini slogans as "Death to Khomeini," Death to the Khomeini Regime," "Long Live Bahktiar" and "Long Live Mujaheddin."

Several Khomeini supports who had gathered outside the bulding shouted "Long Live Khomeini" at the demonstrators.

Some construction workers at a nearby building shouted insults at all the Iranians.

Several State Department officials arrived on the scene as well as FBI agents. Police evacuated the entire building, which is a private office building in which the Algerian Embassy has offices, and did a complete search of it.

Meanwhile, the police and FBI agents set up temporary interrogation rooms in the nearby Holiday Inn where they questioned about 25 students and instructors from the Sanz School, an English language school for foreigners on the same floor as the offices of the Iranian Interests Section.

The Iranian demonstrators were questioned in the third-floor robbery squad offices at police headquarters. The large number of arrests and witnesses forced officials to call in off-duty officers to help with the interviews.

Dozens of uniformed police officers sealed off the third floor and the cellblock area to all reporters and the public.

The arrested Iranians refused to even give their names to police until after they talked to their lawyer, James R. Klimaski, police said.

By midafternoon, they were transported to the federal courthouse where they were being arraigned last night before U.S. Magistrate Arthur Burnett.

Law enforcement officials said that the demonstrators are members or sympathizers of the Mujaheddin, a Marxist Leninist group in Iran that has joined forces with supporters of dismissed Iranian President Abol Hassan Bani-Sadr to fight a guerrilla war against the Khomeini regime. Bani-Sadr is now in exile in France.

Many of the demonstrators were members of a group here known as the Moslem Student Society, and most are students at George Washington University and other local schools, the law enforcement officials said.

The Mujaheddin group largely stayed in the background of last summer's sometimes violent demonstrations by the pro-Khomeini Moslem Student Association and the anti-Khomeini Iran Freedom Foundation, these officials said.

Mohammad Tabatabai, president of the IFF, said yesterday that the demonstrators had opposed the regime of the late Shah of Iran and had initially supported the Khomeini takeover. But now they have become disenchanted with Khomeini.

Tabatabai's group, he said, favors a return to the Iranian Constitution of 1906, which provides for a separation between church and state and widespread freedoms. The Mujaheddian generally favor an Islamic government.