The religious leader of Azerbaijan, the volatile province in northwestern Iran, today ordered a heavily armed band of his followers to release nine revolutionary militiamen loyal to Ayatollah Ruhollah Khomeini who have been held hostage in the offices of a political party here for three days.

Directing supporters to free the militiamen in the name of Islamic unity, Ayatollah Kazem Shariatmadari apparently hoped to avert a major showdown between forces loyal to Khomeini and the Turkish-speaking people of Azerbaijan, the wealthiest region in Iran and the province containing the largest national minority.

But Shariatmadari loyalists in the Moslem People's republican Party, who said they would release the militiamen at midnight tonight, predicted more clashes unless Khomeini removes his representatives here, and confers a greater measure of autonomy on Azerbaijan.

"There's fire under the ashes," observed a longtime political activist here, echoing an old Iranian saying.

Shariatmadari's supporters, armed with machine guns and automatic rifles, captured the militiamen in intense fighting Thursday night. That clash touched off three days of highly charged demonstrations and demands that presented Khomeini with the latest in a chain of divisive and potentially destructive regional uprisings.

Unrest in Azerbaijan is especially troublesome for the central government because the province contains a third of Iran's population, and because Shariatmadari, the region's unchallenged religious leader and occasional Khomeini rival, commands a nationwide following second only to that of Khomeini.

As one of the only religious or political leaders with enough influence to buck Khomeini, Shariatmadari earlier this month recommended boycotting a constitutional referendum favored by the former. The referendum gave Khomeini supreme power in Iran and limited local autonomy.

Known as the cradle of Iran's revolution, Azerbaijan has long taken the lead in national politics. Just two weeks ago, after Shariatmadari's forces here seized the governor's office and television station, antigovernment disturbances broke out in Baluchistan in the southeast, and in Khuzestan in the south.

Aware of the fierce independence of the Azerbaijanis, central government officials sent to this provincial capital by Khomeini have acted with comparative restraint, diplomatically consulting Shariatmadari on religious questions and restricting the number of militiamen assigned to augment local police.

Tension in Azerbaijan reached a flash point again this week, observers here say, because Khomeini reneged on a pledge made during the crisis two weeks ago to fire his three most visible representatives -- the governor general, the head of the Revolutionary Court and the Friday prayer leader.

But the people of Azerbaijan have compiled a long list of complaints against these officials. The complaints can be summed up in 10 words spoken by Hushang Karemi, commander of the Moslem People's Republican Party: "They just don't count us as human beings over here."

Among the allegations by Karemi and other Azerbaijanis:

Political opponents of Khomeini are routinely arrested and are mistreated in jail.

Permits and government services are very difficult for them to obtain without offering favors in return.

Governor General Abdol Hossein Gharavi sold treasured Persian rugs belonging to the governor's office.

Ayatollah Sayed Assadallah Madani, the religious leader who gives Friday prayers in Imam Khomeini Square, is loyal to Khomeini who appointed him -- not to the people's religious favorite, Shariatmadari.

Karemi, 25, who said he commanded a team of 50 terrorists setting fire to banks and seizing police stations during last year's revolution, bitterly protests that the new Islamic Republic that he put his life on the line to create is not much better than the shah's government it replaced.

"I'm sorry I ever made the revolution," he said, standing among a group of gun-toting comrades in the heavily fortified party headquarters where fighting took place Thursday night. "They are doing the same things today. Only it's worse because I know about it.

"Azerbaijan started the revolution, and now they're paying us back," he said sarcastically, pointing out the bullet holes and shattered glass that remained in the run-down party building after the seven-hour gunfight in which at least five men were wounded.

Karemi had demanded release of his party supporters jailed in Tabriz -- he claimed 200 have been arrested since the constitutional referendum -- as a condition for freeing the militiamen. At Shariatmadari's request, he dropped that and other demands.

"Whatever Shariatmadari tells us to do, we're going to do," he said.

A mile away, in the massive governor's office adorned by a large portrait of Khomeini and a smaller one of Shariatmadari, Vice Gov. Asghar Nishabouri disounted the allegations, saying they came from anarchists "who are trying to exploit a split in religious opinion."

"No nationalistic kind of feelings are here," said the vice governor. "These people are the best supporters of Imam Khomeini. The central government has no problem in Azerbaijan. A small group had tried to exploit the nationalism, but the people don't support them."

At Tabriz jail, Abbolfazel Mousavi, provincial head of the Revolutionary Islamic court sat in a small, austere office, and denied arrests of Khomeini's political opponents or mistreatment of any of the prisoners he keeps.

Mousavi, a priest who wore a black turban and tinted glasses, was inattentive during the interview until he was asked about two small rocks, a dagger and a six-inch metal rod that was sitting on top of a floor safe located to the right of his metal desk and an electric space heater.

These weapons, he said, warming to the subject, were confiscated from teen-agers who claim to have received the items from the Moslem People's Republican Party. "They don't know what's happening," he said of the youngsters.

While he was speaking, he motioned to aides sitting across the room. They left and quickly returned. The first assistant brought in two Molotov cocktails in Iranian vodka bottles and placed them next to the rocks.

Mousavi nodded.

A second assistant entered the room carrying a two-food metal rod.

Mousavi smiled.

Finally, a third aide walked into the room holding up two five-foot rods that looked like fence posts.

The last presentation brought out a chuckle.

"Just 15- or 16-year-old kids," said Mousavi. "They're just people making trouble."