Against a background of growing anxiety among policy makers in the United States and the Western alliance, Greece approaches national elections Oct. 18 to decide whether to reject a century and a half of virtually uninterrupted rightist rule and install its first socialist government.

It will be the third election since the 1974 collapse of the military dictatorship and there are indications that Greek voters may now feel secure enough to follow the example of the French and turn to socialism in the hope of alleviating pervasive social and economic problems.

The already acrimonious election campaign has shown the sharp division between the 7 1/2-year-old Panhellenic Socialist movement led by Andreas Papandreou, a former university of California economics professor, and the pro-Western New Democracy party of Prime Minister George Rallis. At issue are questions no less important to the West than Greece's relations with the North Atlantic Treaty Organization and the European Common Market and the continued presence of U.S. military bases on Greek soil.

After the fall of the junta, expectations of a sharp swing to the left did not materialize, as the Greeks voted in New Democracy with an overwhelming 54 percent majority against only 12 percent for the Socialists. A centrist coalition won 21 percent.

The Socialists doubled their support to 25 percent in the 1977 elections, largely at the expense of the centrist parties. Continued fragmentation of the center and growing disaffection with the New Democracy government has led to the Socialists' optimism that they may carry the next vote, under the slogan of "Allaghi," or change.

In an interview at his home, Papandreou said, "1977 was really our victory. The target of becoming the government in 1981 appeared on the horizon." He said a "new vision" emerged in which Greece would follow its own brand of socialism free of the superpowers and move closer to the nonaligned movement.

Causing considerable alarm in some Western capitals, Papandreou defines closing down the U.S. bases in Greece as a strategic aim of his party and says that in principle his party is opposed to Greece being a member of NATO. But in the interview the Socialist leader dramatically moderated past slogans and stressed that his government would want to enter into a dialogue with the allies and the United States over both issues.

"We want to put the issues on the table and start talking," Papandreou said, emphasizing that he does not believe that his party could resolve them within one four-year term.

In contrast to earlier statements, Papandreou also said that the issue of Greece's membership in the European Common Market, of which the Greeks became full members in January, would be tackled not by direct confrontation or unilateral withdrawal, but by negotiating for better terms and in some areas by noncompliance.

"There are escape clauses in the Treaty of Rome. We will use them. It is all within the rules of the game," he said.

Papandreou said that his position on the possible closing of the U.S. military bases in Greece had been "exaggerated and misinterpreted" and that although not abandoning the ultimate goal of dismantling the facilities, he would like to negotiate issues of their control and the quid pro quo of U.S. arms sales to Greece and Turkey.

"We do not wish to have foreign bases in Greece, but we are aware we may have to live with them for some time," Papandreou said. "We don't seek direct confrontation with the United States. We expect to sit down with the American side and address certain concrete questions."

While New Democracy is capitalizing on Papandreou's early radical positions -- "The elections which bring the left to power might be the last free elections in Greece," said one New Democracy vice minister -- the Socialist leader said his government would be a pragmatic one modeled closely on that of the French Socialists.

"Our positions are dictated not by a vision, but by the concrete situation in which Greece finds itself," he said. "The Greek people want change, but they do not want adventure. That's what we are offering--change without adventure."

Defense Minister Evanghelos Averoff, who is vice president of New Democracy and leader of the right wing of the party, responded that "change is a magic slogan, and the most dangerous for us. But we will face it with arguments. When we remind people how they were living 10 and 20 years ago, the majority will understand that there is good and bad change."

He also said his party was "certainly very concerned" over the Socialists' foreign policy program, "but we believe Papandreou will not pull out of NATO. He couldn't do it because of facts. He may make gestures to prove he is more independent than New Democracy within the alliance."

In some NATO-country embassies here, a more pessimistic view prevails of Greece's relations with its allies in the event of a Socialist victory. But there is a wide spectrum of views ranging from fears of a dangerous undermining of NATO's strategically vital southern flank, to a more cautious wait-and-see attitude.

Throughout Greece, there are indications cutting across different social and economic levels that voters are restless over 25 percent inflation, a stagnating economy, inadequate health and social services, a cumbersome bureaucracy, and a quality of life that lags behind that of the other countries in the European community.

Greeks' attitudes toward the nation's prospects as a community member range from uncertainty at best to outright disaffection as consumers are faced with climbing prices and farmers' expectations of common market benefits are not met.

So far in the election campaign the Socialists have concentrated on economic and social issues in the belief that these are the main concern of the voters. Papandreou has promised to "socialize" some key industries such as mining and metallurgy, armaments, cement and fertilizers, steel, banking, energy and public transport. He also wants to introduce worker participation in management, reduce bureaucracy, and decentralize the administration.

While this would mean in some cases nationalization and in others merely reform aimed at promoting efficiency, as in the case of banking, the slogans of Marxism have not figured in Papandreou's vocabulary for some time. Nevertheless Papandreou's attacks on what he terms an "economic oligarchy," and his promises to redistribute wealth, have prompted New Democracy to pin the Marxist label on the Panhellenic Socialist movement.

Averoff, who is minister of both defense and economy, said Papandreou began with a commitment to Marxism to which he returned after a period as "a bourgeois economist in the United States. Having come back to Marxism with several changes in nuance, I believe he is a populist without firm positions," Averoff said.

New Democracy strategy, aimed at the centrist and undecided voters, has concentrated heavily on foreign policy in an attempt to cast the Socialists as a danger to Greece's security. Party leaders argue that severing ties with NATO would turn Turkey, Greece's traditional enemy, into a favored Western ally.

"No small country can afford the luxury of remaining outside of one of the two major military alliances without running the risk of being confronted with adventure," Rallis said. Averoff said Papandreou's commitment to the nonaligned movement and his hardline stand against Turkey "may bring Greece into a very difficult position."

In employing this preelection strategy, which Papandreou has branded as "scare tactics," New Democracy apparently hopes to conjure up recollections of April 1967, when Papandreou as minister of his father's center liberal government was allegedly involved in a left-wing conspiracy within the army. This contributed to bringing about the military coup.

"These scare tactics won't be effective because the government has lost all prestige. . . There is no possibility of a coup. We have nothing to argue about with the Greek armed forces" he said. "There may be assassinations, kidnapings or fires," he added, as he glanced out of the window at trees charred by arson fires widely attributed to the far right.

Papandrou has gone out of his way to appeal to the Army officers, promising them a review of pensions and promotions. The continued presence of New Democracy founder Constantine Karamanlis as Greece's president after the elections may also reassure voters if seen as a possible balancing factor in the event of a Socialist government.

Besides attempting to frighten voters away from the Socialists, New Democracy is relying heavily on the advantage of incumbency, with a flurry of ribbon-cuttings and cornerstone-laying ceremonies all attentively covered by the state-controlled radio and television, as well as the pro-government press.

Papandreou has demanded equal time on television and he is ready to accept a challenge from Rallis to a televised debate.

Papandreou stands on a balcony in Georghiou Square in the Peloponnese port city of Patras, beaming in a shower of confetti as he overlooks a sea of green-and-white flags bearing the rising sun emblem of the Panhellenic Socialist Party, known as Pasok.

It is his kickoff campaign rally and the crowd of 25,000 is chanting, "Pasok and the people to power!"

Papandreou warms up the crowd by evoking deafening cheers with references to the "resistance fighters of Greece" and derisive hooting at the mention of the deposed monarchy and the 1967 colonels' coup. "I believe the election has already been decided," he says. "Change isn't just a slogan. It's what the Greek people demand of us."

The Socialist leader outlined his vision of change by concentrating on domestic issues and referring to the recent election of President Francois Mitterrand in France, saying, "as a government, we will have unqualified support from Europe, which with the double victory of Mitterrand, has embarked on its own road of socialist change."

Papandreou characterized the economic policies of New Democracy as "inefficient, inconsistent and incompetent" adding, "It's not democracy that is in danger, but New Democracy."

Papandreou omitted from his speech the foreign policy issues New Democracy has sought to underscore. He said afterward that he will address these issues in a speech in Salonika later in the campaign. But the Patras crowd cheered enthusiastically at his promises for economic and social reform, and did not seem disappointed that he failed to mention NATO or the U.S. bases.

When asked in the interview whether he felt that he risks alienating the left wing of his party by muting his earlier attacks on NATO, the European Community and the American bases, Papandreou replied, "One thing I feel about these elections is the maturity of the voters. People come up to me and say, 'We know it is not possible to achieve everything you promise, but we are prepared to wait.' "

Papandreou's plan to campaign in 25 towns in 28 days appears designed to bring the Socialists' policies to the more conservative Greek countryside, where the party has already worked hard to establish a network of regional offices.

Apart from the urban areas of Athens and Salonika, almost half of Greece's 9.7 million people live in the countryside, where a system of patronage has been the traditional method of securing political allegiance.

Papandreou clearly hopes his pledges to revitalize the rural economic and cultural life and reverse the trend of young people migrating to the cities or abroad will counterbalance the traditional conservatism of the country dwellers.

But Averoff said the rural voters recognize that a succession of right-wing administrations have dramatically improved their standard of living over the past 20 years.

"If one goes to villages, one can see cars, refrigerators, televisions, where before there was unbelievable frugality," Averoff said. "There has been an unbelievable change in their standard of living. When we point that out to them they will immediately understand. The Greek people are reasonable. They will feel this is the truth and the rest the Socialists' claims a mirage."

In their bid for an electoral majority, both parties have looked to the centrist voters. New Democracy is also attempting to recover the 7 percent of the vote that in 1977 went to the extreme right National Front party. The Socialists, however, are studiously avoiding an appeal to the Communists, who in 1977 gained 9 percent of the vote.

As for forming a coalition to gain the necessary 151 seats in Greece's 300-member parliament, New Democracy has kept open the possibility of an arrangement with the far right. Papandreou on the other hand has rejected the possibility of a coalition with the Communists.

"We feel that either the voters will give us a majority, or things will be very uncertain," he said.

If the Communists muster what is expected to be about 12 percent of the vote, they could end up holding the balance in Parliament and assure Socialist ascension to power even if only by passively supporting the Socialists in an initial motion of confidence. This could bring into play the factor of Karamanlis, who under the 1975 constitution enjoys strong presidential powers with which to try to avert early elections.