Nonaligned Yugoslavia and Greece are quietly discussing the terms of a mutual defense agreement, qualified sources revealed today.

The discussion, which have the tacit approval of NATO, of which Greece is a member, were initiated by Yugoslavia with the aim of securing the 154-mile Greek-Yugoslav border in the event of any foreign attack.

According to the sources, proposals now circulating between the two capitals include a mutual reduction of forces along the border, and an ultimate withdrawal of both armies if either side is attacked. In effect, according to the sources, a demilitarized cordon would be created along their common frontier.

The two sides are also reportedly discussion coordinated contingency plans. Greek purchases of small arms and light artillery from Yugoslavia and small-scale joint maneuvers along the common border.

The closely guarded discussion, which have been under way for the last 18 months have already yielded a discreet exchange of information on military contingency matters. There has also been a flurry of visits between Athens and Belgrade by the leaders of the two military commands, including exchange visits y the commanders-in-chief of the two countries armed forces and an official visit to Belgrade by Evanghelos Averoff, Greece's minister of defense.

Some preliminary decisions on the proposals are expected to be taken later this year when Averoff's Yugoslav counterpart Gen Nikola Ljubicic pays an official visit to Greece.

Bracing itself for an uncertain future after President Tito, 85, dies, the Yugoslavs first cautiously broached the idea of military cooperation with Athens during an official visit of Gen. Stane Potocar, chief of staff of the Yugoslav armed forces, in March 1976.

The talks were further expanded two months later when Tito visited Greece. Prime Minister Constantine Karawanlis, whese foreign policy aim has been the creation of a new. Baikan regional enslave, was reportedly receptive to Tito's idea.

There are high officials in both capitals who reportedly believe that unnecessary losses were suffered by both sides during the two world wars because there was no advance planning between Yugoslavia and Greece. They are said to be urging their respective governments not to repeat past omissions.

Due to local sensibilities, however, both in Belgrade and here, the semantics of the final form of the agreement is almost as sensitibe a subject as the agreement itself. Yugoslavia's nonaligned status precludes its membership in a military pact. Some members of the Greek armed forces are said to fear that an agreement with the Belgrade Communist government that sounds too formal might be misinterpreted in the West.

NATO, however, gave its blessing to the 1954 Balkan pact, in which Greece, Turkey and Yugoslavia pledged to come to the defense of each other in the event of an outside attack, the alliance in securing Yugoslavia's continued status outside the two military blocs.

According to one ranking source, NATO itself is reportedly revamping its defense plans for Greece and Italy, two member countries that share borders with the independent Communist state.

Italy is particularly been on Greece's signing an agreement with Yugoslavia, according to officials here, as the Rome government has its own worries about the Italian Yugoslav border once Tito dies.

Illustrative of the subtle changes in the Balkan balance of power today, the Greek-Yugoslav discussions concern what was once one of the Cold War's most impregnable frontiers. Closed by Tito after his break with the Kremlin in 1948, the elimination of supply and escape routes through Yugoslavia by Greek Communist forces tipped the balance in the Greek civil war.

Today, there is reportedly considerable interest at the highest level of both government for a phased up-grading of their bilateral military ties. Belgrade, fearful that the Kremlin may attempt to exert control over Yugoslavia after Tito's death, has a good deal to gain, according to Western experts.

The Athens government, however, is fearful that any Soviet interference on its northern border could upset the Balkan status quo. and has become increasingly of a hard-line Communist nation emerging on its northern flank.

Moreover, the ongoing Greek-Turkish dispute over the Aegean and Cyprus is of much greater strategic importance to the government here since it brought the two nations dangerously close to war three years ago.

President Tito's pledge on the violability of the Greek border was "absolutely essential" in the words of an official source here.

"We have eliminated the possibility of a second front in any war with Turkey," he continued. "Therefore it is in our interest that we have a secure border with Yugoslavia and, by extension, that Yugoslavia remain non-aligned."

In another ironic juxtaposition, unthinkable in Cold War years, Tito has become an unexpected mediator for the Atlantic Alliance by urging Greece and Turkey to mend their fences and revert to the status of full-fledged NATO allies. The independent Yugoslav leader has a vested interest at stake.

"Yugoslavia does not like the looks of Greece and Turkey throwing the balance of power askelter in the eastern Mediterranean," one Western expert said. "It makes them uncomfortable to have their flanks open and unprotected. Therefore, it's in their interests to do whatever they can in the area to repair the southeastern flank of NATO and return it to its securest possible state."