ATHENS, JULY 8 -- Greek and U.S. officials signed a defense treaty today allowing two major U.S. military bases to remain in Greece for at least eight years.

The treaty, which must be ratified by the Greek Parliament and the U.S. Congress, guarantees defense of Greece's territory against any hostile country, including Turkey, Greece's neighbor and fellow NATO member.

Greece and Turkey have come close to war twice in the past two decades.

The treaty calls for Congress to appropriate $345 million in aid for Greece's purchase of U.S. military equipment. It also proposes that Greece receive surplus materiel worth about $1 billion, said Greek Foreign Minister Antonis Samaras. The United States also would waive $50 million owed by Greece for past military purchases.

A previous five-year defense agreement expired in December 1988. Seventeen rounds of negotiations involving the former Socialist government of Andreas Papandreou produced no treaty. Coalition governments after June and November elections last year put the issue on hold.

The conservative government, elected April 8, and the United States reached agreement in principle on May 30.

The treaty covers two major U.S. military bases on the southern island of Crete: a naval support facility at Souda Bay and Iraklion Air Station near the village of Gournes.

Samaras said the Souda Bay facility will provide refueling for surveillance aircraft previously stationed at Hellenikon Air Base near Athens, which will be closed to save money.

A naval communications station at Nea Makri will be closed and numerous relay stations throughout Greece will be withdrawn.

The treaty could be in effect by September.