The Socialist government of Andreas Papandreou took a significant step away from neutralism and toward keeping Greece a member of the Western strategic camp today when it initialed a new defense and economic cooperation agreement with the United States that will insure the continued presence of American military bases in Greece for at least five years.

The agreement puts off the next opportunity for any Greek government to close down the bases until well beyond 1985, when the Socialists' four-year term ends. Papandreou and the Socialists swept to power in October 1981 on a militantly anti-American platform in which they pledged to close down the "bases of death."

The new agreement may be challenged by either side just before its five-year expiration date. But there is nothing to prevent its extension beyond this date in the absence of such a challenge.

Once it is signed by both sides and ratified by the Greek parliament, the agreement will replace the 1953 U.S.-Greek defense accord that established the bases. As part of the new agreement, the United States has promised Greece $500 million in military aid for next year.

The text of the new agreement has not been released, but it is understood to include a generally worded American commitment to maintaining the military balance between Greece and Turkey. Papandreou said today that Greece had gained the right to "curtail" operations on the bases in the case of "emergency circumstances."

The prime minister also said that the United States had agreed to use the bases only for defensive purposes. It would not, he said, use them against Greece's Arab "friends" in the event of any new conflict in the Middle East.

The two sides reportedly came close to initialing an agreement in June. Negotiations, however, were extended when the Greek government changed its mind at the last minute, apparently out of concern for the reaction from the Communist left and hard-line ideologues within its own party ranks.

The U.S. Embassy said in a statement today that the agreement "provides a good basis for a longer term defense relationship, and as a whole serves the purpose of continuing good bilateral relations across the board."

The tenor of the embassy statement was in sharp contrast to remarks given today by Prime Minister Papandreou, the chief arbiter of Greek foreign policy.

Speaking before Greek and foreign journalists and Cabinet ministers, Papandreou emphasized the right of the Greek government eventually to challenge the agreement. Describing this provision as "unique," he said "it expresses for the first time Greece's equality and proves that to a large degree our national independence has been won."

He added, "The agreement will go into effect by Dec. 31, 1983, at the latest. This means it ends on Dec. 31, 1988, and constitutes a time plan for the removal of the bases, which was our goal in the negotiations. After the end of this period the dismantling of the bases starts."

Analysts here interpreted Papandreou's statements as an attempt to dampen radical left reaction to the accord.

A senior State Department official said in Washington that it is customary for U.S. bases agreements to run for five years, after which either government can seek to renew, end or modify the accord. "To my knowledge, we have not been" notified of any Greek intention to terminate the agreement after the five years," the official said. "It is bizarre to speculate on what conditions will be three or four years from now."

A referendum on the bases issue was called for today by Kharilaos Florakis, general secretary of the Moscow-allied Communist Party of Greece. Senior party officials said earlier this week that the party would reject any accord that did not clearly spell out that the bases were to be shut within the Socialists' term in office. The officials, however, declined to say whether they intend to take their opposition into the streets.

The accord covers four major U.S. bases in Greece, with 3,400 U.S. personnel and a similar number of dependents, as well as about 20 smaller installations scattered throughout the country.

The most important base is the Souda Bay complex on Crete, between Greece and the Libyan coast. It provides port and anchorage facilities for the 6th Fleet, maintains supplies of ammunition and fuel and is linked to a North Atlantic Treaty Organization missile range. An air base at Gournies monitors Soviet activity in the eastern Mediterranean.

An air base at Hellenikon, south of Athens, is also a center for surveillance and reconnaissance missions in the Middle East and the northern Soviet Bloc area. The fourth main base, at Nea Makri, north of the Greek capital, is part of the U.S. global communications system.