The siege of the Iranian Embassy here ended in explosions, flames and gunfire tonight when British Army anti-terrorist commandos stormed the building and rescued 19 Iranian and British hostages.

Britain ordered the assault after the ethnic Arab Iranians holding the embassy killed three gunmen and captured two others of the group that seized the embassy and total of 26 hostages last Wednesday. The gunmen had freed five hostages earlier.

Two massive explosions along with gunfire set the embassy afire and heavily damaged it as the Special Air Service commandos stormed the elegant five-story townhouse facing Hyde Park in London's fashionable West End.

The gunmen, from Iran's oil-exporting province of Khuzestan, reportedly had announced they would kill their hostages one by one on the half hour until their demands were met. They intitially had called for release of 91 fellow Arabs they said were imprisoned by the government of Islamic leader Ayatollah Ruhollah Khomeini. Apparently they had added a demand for safe conduct out of Britain.

[In Tehran, Iranian President Abol Hassan Bani-Sadr declared in a mid-night news bulletin: "The brave resistance of your children in the Iranian Embassy in London has borne its sweet fruit." Noting the release of the hostages, he said, "refusal to surrender brought its result, which is victory." Washington Post correspondent Jonathan C. Randal reported that Iran also announced dispatch of a cable thanking the British government.]

Although some hostages were seriously wounded, police said that all who were still alive in the embassy when the assault began, shortly before 7:30 p.m. (2:30 p.m. EDT), had survived.

One hostage, BBC television technician Simeon Harris, waved a white flag from a second-story window just after the assault began in the fading sunlight of a cool, clear spring evening. Harris then jumped from the terrace atop the embassy's pillared front-entrance portico onto the adjoining terrace of the townhouse next door, where commandos and police waited to enter the embassy.

Gunfire continued and flames and smoke poured out the front and back of the building for half an hour, while the commandos, wearing dark hoods and clothes swarmed through the embassy battling gunmen and helping hostages escape.

Most of the surviving hostages -- 15 men and four women -- came out the back of the embassy, where the main commando assault was mounted. Police brought stretchers around the side of the one-block row of 20 townhouses to ambulances waiting at a safe distance.

Firemen guarded by police with guns pointed at the embassy later moved in behind a retaining wall 100 feet in front of the embassy to begin hosing down the flames.

It was not clear tonight whether the gunmen caused the two explosions, carrying out their original threat to blow up the embassy, or whether the commandos detonated grenades of their own to help shock and overpower the gunmen. Two black-clad commandos appeared to be setting charges just outside the second-floor windows before the second explosion blasted debris, flames and billowing black smoke out the front of the embassy. A towering cloud soon could be easily seen by holiday strollers on busy Kensington High Street and in parts of spacious Hyde Park, a half mile and more away.

The drama at the front of the embassy was watched by millions of Britons in the middle of their prime-time May Day Monday holiday viewing. A BBC camera perched 70 feet above the street on a cherry-picker crane picked up the action live just several hundred yards from the embassy.

The police believed the gunmen also were watching television, which apparently was one reason the assault was made from behind the embassy. Nothing stirred in the television camera's view of the small street in front of the embassy until the first explosion and gunfire was heard from behind it.

Besides the hostage Harris, two others escaped at the outset: Police constable Trevor Lock, who had been guarding the embassy when the gun-overpowered him last Wednesday, and Ronald Morris, a British clerk at the embassy.

Surviving Iranian hostages included charge d'affaires Gholam-ali Afrooz, who reportedly tried unsuccessfully to escape when the gunmen invaded last week by jumping from his second-floor office window to the walled terrace in back. But, according to BBC television producer, Chris Cramer -- one of the five hostages released during the past several days of negotiations -- the gunmen caught Afrooz and dragged him back inside.

The Iranian hostages also had included the embassy's first secretary, military attache, cultural attache and other diplomats. Several of the Iranian survivors were being treated for serious gunshot wounds at nearby hospitals tonight, but none was reported to be critically injured.

The Iranian hostage who the gunmen killed and placed outside the embassy, triggering the British response, was identified as the press couselor Abbas Levasani, 25, who had been at his post here less than six months. The other victim, whose body was found in the building's smoldering interior hours after the assault, was not immediately identified. The British said the gunmen had announced two killings at the time they put Levasani's body in the street.

Scotland Yard police commissioner Sir David McNee said at a press conference late tonight that there was "no alternative" to storming the embassy after police became certain that the gunmen were carrying out today's threat to begin killing hostages until the British government met their demands for safe passage out of the country.

Police stationed near the embassy said they heard three shots, then three more several hours later this afternoon. Police negotiators said they were told over the telephone that these were their first two executions.

In a last attempt to avoid violence, in case the gunmen were bluffing, police brought an unidentified Islamic religious leader to plead with them by telephone.

At 6:30 p.m., McNee said, he sent them a signed letter stating:

"I and my officers wish to work out a completely peaceful solution to the situation . . . It is not our way in Britain to resort to violence against those who are peaceful. You have nothing to fear from any of my officers providing you don't harm those in your care.

"I firmly hope that we can bring this incident to a conculsion peacefully and calmly."

But the gunmen pushed the dead body out of the front door shortly before 7 p.m. Police officers, guarded by sharpshooters, edge forward with a stretcher and carried the body away.

McNee immediately consulted with the British government's command center, headed by Deputy Prime Minister and Home Secretary William Whitelaw. With his concurrence, McNee ordered the assault.

The regiment, whose motto is, "Who Dares Wins," has been specially trained for such operations since terrorist violence became widespread in the sectarian conflict in Northern Ireland a decade ago. Special Air Services troops have operated in Ulster since 1976.

SAS officers also advised the West German military on the successful commando rescue of the passengers of a hijacked Lufthansa jetliner at Mogadishu, Somalia, in 1977. That raid utilized grenades to stun the terrorists and such explosives may have been used here today.

A half-mile-square area around the Iranian Embassy here -- from Royal Albert Hall on the west to the barracks of the queen's horse guard on the edge of Hyde Park on the east -- had been sealed off by police since the siege began.

Hundreds of police officers and the commandos had lay in wait in surrounding buildings, behind nearby walls, in police vans and behind a grassy hill and among trees in Hyde Park across from the front of the embassy.

"The police had waited and negotiated patiently over six days," McNee said tonight. "We had tried every possible means except giving in to terrorism. This we would not do. But we were determined the police would never be the first to commit aggression."

Sitting alongside McNee at tonight's press conference, Whitelaw said, "The operation was an outstanding success. It will show that we in Britain will not tolerate terrorism in our capital a telegram sent here tonight, "I city. The world must learn this."

British officials said they had informed Arab ambassadors here, who had been asked by the gunmen to mediate for them, that "in no circumstances was the government prepared to offer to the terrorists a safe conduct out of this country.

"This would have been directly contrary to our international obligations," a Foreign Office statement said, "and would have made a mockery of our steadfast opposition to the spread of international terrorism."

The British said the Iranian government had been informed of the possibility of storming the embassy earlier during the siege and had responded by requesting Britain to take all necessary measures to safeguard the lives of their hostages.

"We confirmed to their representatives in writing that this constituted the necessary consent for our action," the British Foreign Office said.

Iranian President Bani-Sadr told Prime Minister Margaret Thatcher, "I should like to express my gratitude for the perserving action of your police force that proved its competence during the unjust hostage-taking event at the Iranian Embassy in London."

Iran, although a Moslem country, is not Arab -- although it includes an Arab minority that those seizing the embassy claimed to represent.

British officials said it would take some time to piece together details of the assault, including the cause of the explosions, and to explain how the surviving hostages were rescued safely.

BBC television producer Cramer said after the seige ended tonight that before his release last Friday the hostages had discussed how they would try to escape if the embassy was stormed, which he said they were certain eventually would happen. They were able to make these plans, he said, while the sole English-speaking gunman was out of the room where most of the hostages were held.

Police originally had assumed there were three gunmen, but became convinced by their conversations with the gunmen and some hostages both over the telephone and through open windows of the embassy that there were as many as five.

"The gunmen had hand grenades," Cramer said in a BBC television interview tonight. "One of them was playing with it the whole time. He had his finger through the pin all the time."

Cramer said constable Lock had told him he still had his gun because the gunmen had not searched him after invading the embassy last week, apparently because most British police officers are known not to be armed.

"I said, 'Where is it exactly and how do I use it?'" Cramer recalled. Lock answered, according to Cramer, "There's no safety catch on it, and if you want to use it, just take it out and it fires. But you can't use it. We could only take two of them."

In addition to the three dead gunmen, another was wounded and the five was placed under arrest.

Tonight's sudden violent end to the slow motion drama during the sixth day of the siege occurred in full view of assembled relatives of the Iranian embassy hostages whose screams could be heard above the rattling gunfire and shouts of police and reporters.

Outside police lines, scores of Iranian supporters of Ayatollah Khomeini had been demonstrating there since the seige began. They continued their chants during the assault. Afterward, they tried to break through police barriers and were chased and tackled by officers guarding the perimeter.

Staying behind police lines, counter-demonistrators, including teen-aged London "skinheads," continued to shout anti-Khomeini slogans at the Iranian demonstrators as they had most of the this holiday weekend.