While continuing to negotiate with the United States on the future of its 26 military installations on this southeastern flank of NATO, Turkey is also attempting to maintain a rapport with America's currently most bitter enemy, the revolutionary theocracy of Ayatollah Ruhollah Khomeini.

To assure financing for a costly and sorely-needed modernization of its 500,000-man armed forces, Turkey will be obliged to allow the United States to keep the installations. One, at the Incirlik base near Adana -- within easy striking distance of Iran -- includes a nuclear-equipped tactical fighter-bomber squadron.

But, to keep hope alive for wheat-for-oil deals with Iran and to continue collaboration with the Iranian government over controlling the Kurdish struggle that has spilled across the border, Turkey cannot afford to affront its Islamic neighbor to the east.

When questioned recently about what Turkey would do if the United States asked if it could launch a military offensive against Iran from here, Prime Minister Suleyman Demirel sidestepped the issue by saying that the United States had not asked the question. It appears unlikely, however, that he would permit Turkey to serve as a jumpoff for any U.S. intervention in the Gulf because of the risk of becoming estranged from the Moslem world.

With a critical balance-of-payments problem, a steadily deteriorating economy and a wave of political terrorism that has brought this overwhelmingly Moslem country to the brink of anarchy, Turkey can ill afford such an estrangement. Turkey's population is 98 percent Moslem.

But the stakes are also high for the United States, which depends on its installations here to collect an estimated 30 percent of its electronic intelligence on Soviet space centers, nuclear tests and fleet movements. The importance of these installations has obviously grown since the United States lost its monitoring facilities in Iran.

The major stumbling blocks over an agreement to extend the installations have been Turkish demands for equal sharing of the bases, the conditions under which U.S. forces could use them for attack and the amount of military and economic aid Turkey is to receive in trade-offs.

As the diplomatic negotiations lumber along at the diplomatic level, political undercurrents of a more grass-roots nature are also at work in Turkey, and some bear on the Iranian question.

Islamic extremism here does not even begin to approach the level of Iran, but there have some early signs of such revivalism, although overt expressions usually are kept in check by martial law.

As a result of accelerated urbanization and the same kind of internal migration from the provinces to the cities that helped foment Iran's turmoil, there is a growing base of restive, disillusioned youth in Turkey susceptible to Islamic fundamentalism and policial extremism. Half the population is under 25 and a quarter is under 15, and political analysts agree this will have to be reckoned with sooner or later.

Terrorism in endemic -- there is an average of 10 political assassinations a day -- and much of the killing is done by young men who identify either with the extreme right or the extreme left. Provincial grudges and almost clannish animosities also appear to motivate many of the assassinations.

The government, demonstrably unable to stem the rate of terrorist killings, probably would be hard pressed to cope with any surge of Islamic extremism if it took a violent turn.

The most likely catalyst for such a development would be leftist and anarchist extremists who are bent on proving that Turkey's democracy has failed, although they have yet to identify in any organized way with Islamic revivalism.

The key leader of Moslem fundamentalism in Turkey is Necmettin Erbakan, leader of the National Salvation Party, whose support Demirel needs. The devout Moslem religious vote in Turkish elections is about 15 percent, most of which comes from the NSP.

But Erbakan faces imprisonment if he openly advocates an Islamic republic, and therefore he is limited as a rallying figure for any fundamentalist surge.

There are other reasons, however, why Turkey is not likely to become the "next Iran" -- at least not for several years.

For one thing, Shites are a minority of 10 to 15 percent of the dominant and more secular Sunni sect of Islam in Turkey and even they are more modern than their brethren in Iran. Traditionally, religion has been less intense here.

Moreover, Turkey has a democratic system -- however problem-plagued -- in which a majority of Turks still have faith. Seventy percent of the electorate went to the polls on Oct. 14, and 47 percent voted for Demirel's conservative Justice Party, which is about as far removed from the Khomeini genre of extremism as it could be.

There have been a few anti-American flareups here, but they have been strictly controlled by Turkish security forces.

However, U.S. diplomats and Turkish government officials agree that the intensity of future political and religious extremism could hinge on how delicately Turkey continues to navigate during this period of confrontation between Tehran and Washington.