At a time of spreading Middle East terrorism aimed mainly at U.S. interests, it seems extraordinary that the one thing the United States and the Shiite extremists who hijacked the TWA plane appear to have in common is almost complete faith in the government of Algeria.

The United States, which turned to Algeria 4 1/2 years ago to mediate the rescue of U.S. hostages in Iran, once again has found itself heavily beholden to the North African nation for a similar mission -- this time on Algerian soil.

U.S. officials put heavy diplomatic pressure on Algeria to allow the hijacked plane to land in Algiers because of their confidence -- based on the Iranian hostage experience -- in that government's diplomatic skills to deal with the crisis, if any Arab government can. In addition, there was considerable concern in Washington that the hijackers might otherwise set down in Libya, whose leader, Muammar Qaddafi, is a sworn enemy of the United States.

The hijackers, upon landing a second time at Algiers airport, issued a communique hailing Algeria as the only country that understands their cause and thanking the Algerian and its leader, Chadli Bendjedid.

"How we wish that the Arab countries would follow the example of Algeria for unity, for the defeat of world imperialists and the liberation of Palestine," they said.

In late 1980, it was the Islamic revolutionaries in Tehran holding 52 U.S. hostages who set the precedent of turning to Algiers as an acceptable intermediary with Washington. Algeria negotiated release of the hostages as well as a complicated accord on claims filed by Iran and the United States.

U.S. officials from President Carter down hailed the extraordinary negotiating skills and "creative mediation" of the Algerians.

In this crisis, it is the hijackers' respect for Algeria's revolutionary past -- a successful eight-year war for independence against France and the championing of numerous Third World causes -- that apparently explains their decision to fly there in the first place and then to return to Algiers again rather than remain in Beirut, a seemingly safer haven.

The relationship between Algeria, a former militant Third World leader, and the United States is one of the more remarkable forged by either country in their almost diametrically opposed foreign policies, particularly under the vehemently anti-Soviet Reagan administration.

Furthermore, with the state visit of Algerian President Bendjedid here last April and the U.S. decision to sell arms to his traditionally Soviet-supplied military, ties between the two appear to be taking a turn for the better.

The new, closer U.S.-Algerian political connection comes against a long history of diplomatic ups and downs. Initially, Algerians felt a deep distrust for this country.

Immediately after Algeria became independent in 1962, its first leader, Ahmed Ben Bella, angered Washington by flying directly from a meeting with President Kennedy to Cuba, where he proclaimed his support for Fidel Castro, then caught in the midst of the U.S.-Soviet missile crisis.

At the start of the 1967 Arab-Israeli war, Algeria, then under the leadership of Houari Boumediene, broke diplomatic relations with Washington out of anger with its support for Israel. Relations were not restored until 1974, after another Arab-Israeli war the previous year.

Until his death in 1979, Boumediene kept Algeria in the forefront of the nonaligned movement.

Bendjedid, a fatherly ex-military officer, took over upon Boumediene's demise and has slowly set about reorienting his Soviet-armed and socialist-oriented nation toward the West.

His trip here in April for talks with President Reagan was a milestone in this reorientation. Viewed as a big success by both sides, the state visit opened for the first time the possibility of American arms sales in Algeria and far closer economic and political ties between the two countries.

Algerian officials said at the time that they were somewhat overwhelmed by the strong show of interest by the Reagan administration.

The value of the new U.S.-Algerian connection to Washington is now becoming clear, sooner than most administration officials probably expected.

Having acceded to Washington's entreaties to allow the hijacked TWA plane to land at Algiers airport -- reversing its initial decision not to become involved -- the Algiers government now finds itself in the middle of an extremely delicate situation.

Since their long negotiations with France for independence in 1962, the Algerians have had a reputation for having a highly professional diplomatic corps and for being extremely good negotiators and mediators.

Their skills, it appears, are now being put to the ultimate test.

An Algerian diplomat here described the negotiations held on the plane yesterday between two Algerian diplomats and the Shiite hijackers as "very tough."

He described the Islamic extremists as "very young, very suicidal and very tough" and stressed the use of psychology in dealing with them and "keeping them talking."

According to various television and radio reports, the Algerians were said to be relying on the Koran, the Moslem holy book, and various religious arguments in their bid to convince the hijackers to release the remaining passengers.

The Algerians were not thought to be anxious, however, to force the hijackers to remain at Algiers airport by shooting out the TWA plane's tires or some other show of force, out of concern for maintaining their good relations with both the Lebanese Shiites and Iran