For much of the past eight years, many Americans have been able to watch the Iran-Iraq war with a certain sense of detachment. After all, here were two countries that seemed to deserve each other, locked in a no-holds-barred military stalemate that offered the not-unpleasant prospect of exhausting both nations.

Of the two countries, it is Iran that has dominated American attention since the war began. Americans had a special reason to detest the Iran of Ayatollah Ruhollah Khomeini ever since his Shiite revolutionaries stormed the U.S. Embassy in 1979. Iraq was a less-obvious villain, even though it had broken relations with the United States after the 1967 Arab-Israeli war and was for many years on the State Department's list of countries that support international terrorism.Yet now, as the war draws to a close, it may be wise to widen our view - beyond the visceral antagonism toward Iran - of who did what to whom in the gulf war. This is a war that has broken new and old ground in grisly weaponry and tactics, and most independent chronologies point to the same conclusion: At crucial points, Iraq was the primary instigator and escalator.

The war between Arab Iraq and Persian Iran that began in September 1980 accentuated the turmoil in the region already stirred by Khomeini's revolution. But as the conflict continued and the world somehow did not explode, the war produced a certain numbing effect. Oil tankers were sunk and insurance rates went up but nothing much else happened. In a way, this testified to the resiliency and general good sense of the rest of the world. The speculation of 1980 that events in the oil-rich gulf war zone could touch off a superpower confrontation or even World War III proved to be wrong.

Yet the fact that these dire events did not happen, and the prospect that the war may now finally be coming to an end, should not numb us from thinking about the grim military precedents of this struggle, who introduced them and where they leave us.

The eight-year war reintroduced the dreaded use of chemical warfare against military and, inevitably, civilian targets, something that the world thought it was rid of after World War I. It produced massive aerial bombing and missile attacks against cities, and a direct challenge to freedom of the seas, commerce and navigation through hundreds of attacks against the shipping of non-belligerents. Floating mines were seeded indiscriminately in sea lanes in another throwback to a form of warfare most thought had been discarded. And a more modern weapon - medium-range ballistic missiles that ultimately could be armed with poison-gas warheads - spread throughout the region.

There is some legitimate dispute about who did what to whom first. And as seen from Iraq and other Arab nations of the gulf with sizable Shiite Moslem populations, the threat posed by Khomeini's declared intent to spread his fundamentalist revolution throughout Islam was very real. But the troubling history of this conflict would appear to place a heavy burden on Iraq, which has set some dangerous new precedents for regional conflicts:

- Iraq began the all-out phase of the war with a massive, three-front invasion of Iran and heavy air strikes against Iranian airfields on Sept. 22, 1980. This Iraqi invasion followed a period of clashes along the disputed border between the two countries and shelling by Iran.

- Iraq opened what came to be known as the "tanker war" in March 1984, with attacks on oil tankers of many nations (not just those of Iran) whose vessels were thought to be carrying Iranian oil to market. The tanker war was a bid by Iraq, which could still export its oil by pipeline overland, to shut off Iran's source of revenue to support the war.

By July 1987, more than 325 tankers had been damaged or attacked in the war. That was the date when the U.S. Navy intervened and began escorting tankers of Kuwait, an ally of Iraq, even though Iraq had carried out almost twice as many attacks against shipping as had Iran.

- The "war of the cities," meaning attacks by warplanes and missiles on the civilian populations of Tehran, Baghdad and other cities, is generally marked as having begun (as a continuing tactic) in March 1985, with Iraqi air attacks on the Iranian city of Ahwaz. Iraqis argue that bombing by Iranian planes of Baghdad on Sept. 23, 1980, started the war of the cities. But that raid came just a day after the Iraqi invasion of Iran. Throughout the war, but especially in the last three years, Iraq has used its superior air force and missile arsenal to carry out far more widespread and devastating raids on Iranian cities than Tehran has been able to mount.

- Iraq resorted to chemical weapons such as poison gas early in the war and continues to use them to devastating effect, including the killing of hundreds and possibly thousands of people in the Kurdish area last March, according to U.S. and U.N. officials.

- Iranian mines presented a temporary embarrassment for the U.S. fleet in the Persian Gulf. But the big tolls for the United States in lives and humiliation came directly, and indirectly, from Iraq.

It was an Iraqi warplane that fired French-built Exocet missiles into the USS Stark in May 1987, killing 37 U.S. sailors. Iraq quickly apologized and called the incident unintentional. But the Stark episode put a hair-trigger on future responses by American warship commanders to unidentified threats mixed into the chaos of the gulf's narrow confines and packed air and sea lanes.

The tragic downing of Iran Air flight 655 with 290 people aboard on July 3 by a missile fired from the USS Vincennes was, in hindsight, an accident waiting to happen, as a lot of people have since called it. The Vincennes was in the gulf because Washington had responded to the clever diplomacy of Iraq's ally, Kuwait. The U.S. fleet had, in a way, become an adjunct of Iraqi military strategy to prevent Iran from interfering with the oil- and gas-tanker traffic of Iraq's financial allies.

Ironically, the downing of the jetliner, combined with quick and astute U.S. diplomacy in the form of an expression of regret and offer of reparations to families by President Reagan, appears to have played a role in Iran's decision on July 18 to abide by a year-old U.N. call for a cease-fire. The real reasons why Iran wants to call the war off now of course run much deeper. But the downing provided at least a fig leaf for Iran, and the price was paid by the Iranian civilians, the U.S. Navy, and a stunned American citizenry.

What the legacy of this war will be is hard to say with any certainty.

If there is a winner, it is probably Iraq. It has held off the counterattacks of Khomeini's hordes and stopped at least temporarily the spread of radical fundamentalism. Baghdad has mended its fences to some degree with the United States, maintained its military-supply relationship with Moscow and emerged militarily stronger - especially in its armored, aircraft and missile forces - than Iran. Iraq is now likely to play a bigger role in the Middle East and be even more on the minds of its other arch-foe, the Israelis.

Iraq also has big war debts, probably tens of billions, and will be in a rush to exploit and export more and more of its oil reserves, perhaps raising conflicts with other gulf states such as Saudi Arabia with different views on oil production.

It is the military legacy, however, that is apt to be most important; in particular the breaching of the barrier against use of gas and chemical warfare. Iraq has used these weapons effectively and terrifyingly to stop offenses that it may have otherwise lost. But what may not be lost is a message to other countries, especially poorer Third World nations, that this repugnant but cheap and effective weapon is on the loose again. Should chemical warheads be combined with the influx of Soviet and Chinese-built missiles into the gulf region, one more nightmare will be added to the Middle East.