Pope John Paul II, still basking in the afterglow of his triumphant tour of the United States, will arrive in this almost exclusively Moslem country Wednesday amidst extraordinary security and no small measure of carefully concealed embarrassment on the part of his Turkish hosts because of the visit's timing.

While publicly extending a red carpet welcome to the pope, the month-old government of Prime Minister Suleyman Demirel is engaged in protocol acrobatics in an effort to minimize the religious nature of the papel vist at a time when Islamic fundamentalism has exploded in such nearby Moslem countries as Iran, Pakistan and Saudi Arabia.

The pope's stated purpose in coming here is to further progress toward reuniting the Roman Catholic and Eastern Orthodox Churches, which separated in 1054. The ecumenical drive was given a major impetus when Pope Paul VI and Patriarch Athenagoras embraced in their historic meeting in Jerusalaem in 1964.

The Turks have chosen to stress John Paul's role as a head of state, rather than a religious leader, and thus underscore the secular and democratic nature of modern Turkey. Turkish arrangements for the pope's visit will emphasize the distinction throughout his three-day stay in Ankara, Istanbul and Izmir, near the ancient Greek city of Ephesus.

Moreover, in sharp contrast to the constant public exposure during his American visit, Turkish security authorities plan to keep John Paul out of sight as much as possible because of fears of an assassination attempt. Terrorist killings have become endemic in Turkey, and Armenian extremists have warned the pope not to come to this country.

Since many Turks view the orthodox patriarch at Istanbul as a vestige of the Byzantine world and a reminder of Greek dominance, the pope's call on Dimitrius I, who is titular leader of some 300 million followers of Eastern Orthodoxy, is being billed in a government outline of the trip as "meeting with the leaders of various religious communities" of Istanbul.

Many Turks remember with some discomfort the first papal visit to Istanbul in 1967 when Paul VI fell to his knees and prayed in St. Sophia's Church, one the spectacular edifices which the Turks had converted into a mosque before turning it into a museum. Government officials privately expressed hopes that John Paul would not repeat the gesture.

With Khomeini talking about jihads (holy wars), the Turks don't want to give the fundamentalists anything to coalesce over," said one Western diplomat, referring to Iran's theocratic ruler, Ayatolliah Rurollah Khomeini.

Turkish Foreign Ministry officials and Western diplomats agree that the Demirel government's main objective is to keep the papal visit as uncontroversial as possible to try to reap a tourist bonanza in its wake.

The government is proud of the world attention it will receive and not at all displeased at the opportunity to demonstrate that Turkey is a democratic secular state that allows all religious minorities to live side by side with the 45 million Moslems here.

At the same time Turks maintain a basic defensiveness about Eastern Orthodxy, regarding the Christian and Islamic worlds as fundamentally different and therefore, somewhat competitive to a degree.

While welcoming their close association with the West, they at the same time tend to seek closer ties to the East. To the average Turk, the Christian world begins at the Greek border.

"There will be no problems as long as the pope keeps in mind that he is coming to Istanbul not [the city's name in the Byzantine era] Constantinople," editorialized Hurrivet, Turkey's highest circulation daily newspaper.

While Islamic extremism here does not even approach the level of Iran, there have been some early signs of such revivalism, although overt expressions of it usually are kept in check in many parts of the country.

So far, Necmettin Erbakan, leader of the Moslem fundamentalist National Salvation Party, whose parliamentary support Demirel needs, has been cautious enough not to openly call for an Islamis revolution. But last Saturday, in a demonstration in Kysiri, several thousand of his supporters openly chanted for an Islamic republic, according to diplomatic observers, Moreover, participants in a recent anti-American demonstration at the U.S. mconsulate at Izmir were said to have included a number of Iranian students from an Islamic seminary.

But the fundamentalist Shiite sect of Islam, unlike in Iran, is a minority of 10 to 15 percent of Turkey's population. And the Shiite offshoot here, called Alevis, are more modernized and far less devout than their counterparts in Iran.

The dominant Sunnis are broken into numerous sects but they also tend toward secularism and many of them regard Khomeinis an aberration.

Turkey aslo does not have the religious infrastructure that made Iran's Islamic revolution possible. When Ataturk, the founder of modern Turkey, launched his modernizing reforms in the 1920s, he dismantled the religious hierarchy by institutionalizing it within the government. As a result, government-salaried religious leaders have not been albe to accumulate the influence and power that they have in Iran.

Partly for these reasons, the United States does not find itself here in a situation even remotely as precarious as some other Moslem countries. When the State Department yesterday announced a withdrawal of nonessential diplomats and dependents from 10 Moslem countries, Turkey was not on the list.

A U.S. source said today that this is because the mission has absolute faith in the Turkish government's readiness to prevent a takeover and some confidence that massive demonstrations against the U.S. Embassy are unlikely unless the United States intervenes militarily in Iran.

But because of the volatile nature of extremism coupled with widespread ineptness and political divisions in the security forces, the papal visit has caused considerable trepidation in official circles here.

A rightist terrorist jailed recently in the ambush killing of a prominent Turkish journalist escaped yesterday from a maximum security military prison, and rumors have circulated widely that he has threatened to make an attempt on the pope's life.

Although the pope and his entourge will be greeted by President Fahri Koruturk in a military ceremony, attendance at the airport arrival, even by Catholic and Orthodox leaders and Vatican envoys, is being sharply curtailed for security reasons. The pontiff will forego the usual motorcade and will be whisked by helicopter to the presidential residence for meetings with Demirel and other Turkish leaders.

Similarly tight security will surround the pope in his visit to Istanbul on Thursday, where he will meet Patriarch Dimitrius.

Ephesus, where he will visit Friday, was the site of the Third Ecumenical Council, which proclaimed in 431 that the Virgin Mary must be called the Mother of God. The decision created a schism with Nestorianism, named for Bishop Nestorius of Constantinople, which maintained that Jesus was born a man.

A decision taken at the Second Council in 381 recognized that the bishop of Constantinople had rights equal to those of the bishop of Rome. This position was ratified at the Fourth Ecumenical Council in 451 which assigned to the eastern bishop's jurisdiction a large part of eastern Europe and Asia.

The two great sees were divided over theological and political differences in 1054. The city of Constantinople fell to the Turks in 1453 and became the capital of the Moslem Ottoman Empire.

In recent times the Catholic doctrine of papal primacy has been an obstacle to Catholic-Orthodox unity, but John Paul said that Pope Paul opened the door to an end of the East-West schism when he met Patriarch Athenagoras in 1964. That was the first meeting between a pope and a patriarch in more that 500 years.

John Paul's visit to Turkey will be his fifth trip outside Italy since he became pontiff on Oct. 16 last year. He has traveled to the Dominican Republic and Mexico, to Poland and to Ireland and the United States.