To the secretive rulers of Iraq, who have struggled for years to build internal stability and hold together the disparate elements of their fractious nation, the revolution in neighboring Iran was an unpleasant surprise.

Nonetheless, Iraq hailed the success of the Islamic rising led by Ayatollah Ruhollah Khomeini and moved quickly to establish good relations with the new goverment.

Recognizing the new government the day after it seized power in Februray, Iraq said it "supports and sympathizes with the struggle of the brotherly neighbor people of Iran for freedom, justice and progress."

Iraqi officials now dissociate this country from the former regime of the shah, with whom they worked closely despite wide ideological differences, and they praise the pro-Arab stance of Khomeini and his followers.

Conveniently overlooked is the fact that early last year Iraq expelled Khomeini, who had lived here in exile for many years, because Baghdad wanted no trouble with the Iranian imperial rulers who had guaranteed a long, stable frontier on Iraq's troublesome eastern flank.

After Iraq's startling reconciliation with Syria last October, The Baghdad government, long a source of dispute and suspicion in the Middle East because of its absolutism and itsreputation for exporting revolution, had, for the first time, stable and cooperative relations with all its neighbors. Then the Iranian revolution threatened to bring down that carefully constructed edifice.

The government's official position is that there is no possibility of Iran's disruptions spilling over into Iraq. Therefore public statements and the official news media take the position that all is well.

Senior diplomats and other sources, however, report that the Iraqis were deeply concerned about events in Iran because those events raised the possibility that Iraq's restive Kurdish minority, its communists or its Shiite Moslems or all three, would be stirred into action by the new wind blowing from the east.

"The Iraqis and the Khomeini people respect each other," a senior diplomat said, "and the new Iranian government has given assurances. But that doesn't mean all fear has subsided. They are convinced that the revolution is not finished and they are not sure the power will stay where it is."

"The Iraqis had a good working relationship with the shah and they didn't want to plunge into the unknown," said another. "But they underestimated the strength of the revolution."

Politically the new Iranian leadership is much more palatable to the Iraqis than was that of the shah. The new Tehran government has cut the shah's ties to Israel and thrown its support behind the Arab and Palestinian cause as represented by the hardliners. It has also abandoned the ambition that always irritated Iraq.

But ever since their agreement at Algiers in 1975, the shah had offered the Iraqis something the new government cannot - a powerful protective force that prevented arms from reaching Kurdish insurgents in the north and firmly repressed communists. Condemned as cynical and praised as realistic, it was a partnership that worked for the convenience of both sides.

The Iranian revolution obliged the Iraqis to readjust their policies, and now the partnership with the shah is being written out of the history books.

Tarek Aziz, a senior official of both the government and the ruling Arab Baath Socialist Party, said in an interview that "the history of Iranian-Arab relations was a history of doubt, conflict and aggression. Iran had its policy of being the policeman of the Gulf and its ambition to expand its interests."

The shah, he said, "did not respect the agreement between Iraq and Iran. He kept many dissidents in Iran, allowed them to act against the interests of Iraq, so we've not sorry." In particular, he said, agents of SAVAK, the shah's secret police, fomented the riots among Iraqi Shiite Moslems two years ago.

Experienced diplomats here and sources outside Iraq familiar with those events said there is nothing to support the accusations that the shah failed to honor his agreement with Iraq or was trying to undermine the Baghdad government.

On the contrrary, they said, the shah scrupulously avoided making trouble for the Iraqis, who had enough of their own at home.

According to Iraqi officials, Western diplomats and Arab journalists here, the Iraqi regime has encountered three main pockets of unrest and opposition in its determined drive to impose order on the country and make all Iraqis march to the Baathist anthem. The three are the Kurds, who fought an armed rebellion in the northern mountains until the shah withdrew his support and closed the border; the Shiites, who represent about 52 percent of the population but hold a minority of the positions of power, and the communists, whom the Baathists have sought to tame with a series of bloody repressions over the past decade.

All these disputes predate the Iranian revolution by many years, but what the Iraqis reportedly feared was that they could be revived by the events in Iran.

What they feared, according to informed sources, was that the Iraqi Shiites would seek more political power through confrontation with the government, that concessions made by the new Iranian government to Iranian Kurds would lead to new demands among the Kurds of Iraq, and that the communists, given some freedom to maneuver by the breakdown of discipline in Iran, would make headway with a new campaign taking advantage of the relatively lower status and poorer living conditions of Iraq's Kurds and Shiites.

So far, none of that has happened.

The three provinces of the nominally autonomous Kurdish region of Iraq, where the Baathists have followed a carrot-and-stick policy of massive economic development and a heavy military presence, are generally quiet.

The government has staged a new crackdown on the communists, closing their paper and arresting 27 alleged communist organizers in the Army.

The government has continued its policy of courting the Shiites by showing respect for their religious practices and emphasizing social welfare benefits and housing assistance over heavy industry development, diplomatic analysts say.

Nor are the conditions here analogous to those in Iran.

The Iraqi Moslem clergy rarely have personal followings and they are government employes, carefully guided in how far they can go and what they are permitted to say. When the Iraqi news agency announced recently that all the country's mullahs had preached the same sermons attacking the Egyptian-Israeli peace treaty, no one doubted that they had.

Nor, according to diplomats and Iraqi official statements, is there any genuine repression of religious activity here, so long as it is kept separate from politics.

With the Kurds disarmed, forcibly resettled in accessible new villages under Army supervision and buttered up with jobs and development money, the threat of a new armed insurgency among them seems remote.

According to diplomats here, the real threat comes not from the Kurds or Shiites as such, but from the fact that tens of thousands of both groups have migrated to the cities where they form a kind of urban proletariat, vulnerable to communist agitation for social and economic, not religious or ethnic, reasons.

That is why the Baathists stress party orthodoxy as the overriding concern.

"In this country," a government official said, "your own personal religion is up to you but the religion of the party is obligatory."

Ticking off the names of Kurds, Christians and Shiites who have risen to prominence, he noted, "Arab or Kurd, Sunni or [Shiite] it doesn't matter, as long as you are politically correct." CAPTION: MAP, no caption, By Dave Cook-The Washington Post