The government announced tonight that Ayatollah Ruhollah Khomeini was finally free to return to Iran and the Moslem cleric now plans to arrive Thursday from Paris on his home-coming trip, ending more than 14 years of exile.

Motorists honked their horns in joy when Tehran radio broadcast the official authorization for his much-delayed return, which lessened the looming threat of civil war.

Diplomats said the way for Khomeini's triumphant return was paved by an 11th-hour agreement between his top aides and two senior military commanders. The agreement was formally approved by the Cabinet tonight.

Despite the breakthrough, the U.S. Embassy earlier in the day issued the stiffest evacuation orders to date in the face of growing anti-Americanism.

All government employes' dependents were "ordered to depart Iran temporarily at the earliest feasible date" and families of private American citizens and "nonessential" Americans were "urged" to do likewise.

Three U.S. military aircraft flew about 200 Americans out today from Tehran's airport, which was reopened after a six-day closure to prevent Khomeini's return.

Five further military flights in addition to commercial airliners were expected to leave on Wednesday.

As recently as last October the U.S. community stood at 42,000 but it has shrunk to less than 10,000.

Khomeini accepted the new proposal largely because, unlike earlier compromises he had rejected, this one constituted clear victory over his adversaries here.

Diplomats noticed that the new agreement covered only establishing of a joint committee of government officials and religious leaders to organize security arrangements for the 78-year-old ayatollah's arrival.

This formulation was at best a face-saving operation for Prime Minister Shahpour Bakhtiar, reported to be a deeply humiliated man as the false hopes of a more favorable deal were dashed at the last minute by Khomeini's Paris entourage at the weekend.

Its main virtue was that Bakhtiar's government was at least included in the arrangements rather than having them made entirely by the religious leaders who could thus claim governmental legitimacy.

But Khomeini aides here said tonight that the government role would be limited to security at the airport itself.

Diplomats also noticed that the deal omitted a condition which had bedeviled previous compromise proposals -- that Khomeini pledge not to establish a provisional government rivaling Bakhtiar's Cabinet.

Key generals were still determined to arrest anyone named to such a provisional government. which Khomeini has threatened to establish for the past several weeks, diplomats said.

A source close to the government said Bakhtiar's greatest secret worry now was that Khomeini would seek a direct deal with the military which would bypass his government.

This would risk splitting the increasingly restive armed forces between strongly pro-shah loyalists and those willing to go along with the ayatollah, the Persian term for religious leader.

The source acknowledged that the Bakhtiar's officials have had to drop the idea of negotiating any long-range deal in Paris with Khomeini and now realize that they would have to negotiate with him here.

Diplomats said that Bakhtiar and his advisers hope Khomeini, after his return, will remain quiet for a few days to allow such negotiations to take place.

The threat of imminent armed insurrection and changing perceptions of all parties concerned -- the military, Khomeini and Bakhtiar -- help explain the success of the current negotiations. The talks, which started yesterday, lasted until late into the night and probably into today.

Negotiating for the military were Lt. Gen. Abbas Gharabaghi, chief of the supreme commander's staff -- Iran's top soldier -- and another senior officer.

Represinting the ayatollah were Mehdi Bazargan, Khomeini's number one troubleshooter, and at least one Moslem cleric.

Top commanders are increasingly concerned about unraveling discipline and open support for Khomeini in the ranks. There is some question whether troops will still follow orders to shoot.

Symptomatic of this was the disabused comment of one general.

"You can't use the Imperial Guard for everything,c he Imperial Guard for everything," he was quoted as saying of the shah's elite self-contained divisional force.

Commanders, who only weeks ago considered Khomeini the devil incarnate, now have talked themselves into letting him come back in the name of preserving sorely strained military unity.

The prime minister basically has struck the best deal he can, according to observers. He still hopes to hang on. He feels his best chance of survival lies in dealing with Khomeini here in the hope that Khomeini, after 14 years in exile, will discover just how unstable the situation could become unless a negotiated settlement can be reached.

Bazargan and other Khomeini aides here, who originally were horrified at the ayatollah's decision 10 days ago to accelerate his return before they could smooth things with the military, now believe the sooner he returns the better.

Privately they make no secret of their hopes that once home Khomeini will listen to the more conservative religious leaders increasingly worried that the country drifts towards chaos, anarchy and armed insurrection.

Today, demonstrators marched through Tehran streets as word spread of the unfolding deal allowing Khomeini to return.

Thousands of Iranians once again milled around Tehran University where they shouted slogans such as "Jihad" or holy war, "Carter is Bakhtiar's boss" and "Huyser is the ringleader of the Iranian generals."

U.S. Air Force Gen. Robert Huyser, the number two American general in the North Atlantic Treaty Organization, has been here since early this month and has played a key role in telling his Iranian counterparts that Washington will not countenance any putsch.

The American Embassy deicsion on evacuation came in the wake of three recent incidents.

Sunday night, Maj. Larry Davis, attached to the American military mission here, was wounded by two small calibre revolver bullets fired by a lone assailant at close range as he returned to his north Tehran home. He was hit in the arm and is reported in satisfactory conditon at the U.S. Army hospital here.

Yesterday, as an American officer crossed the embassy motor pool, an assault rifle was shoved in his stomach by an Iranian soldier guarding the compound. The soldier shouted "Yankee go home." When the full guard was changed at embassy request, the original 60-man contingent shouted, "Yankee go home" as they drove off in their truck.

In Isfahan, the country's second largest city and once the home of 11,000 Americans, U.S. consul David Mcgaffey was beaten yesterday by a mob and required eight stitches in his head when he interceded on behalf of an American earlier involved in an argument with an Iranian taxi driver at a local hotel.

U.S. officials said the American, an employe of Bell Helicopters, shot and wounded the taxi driver, then fled to Hotel Koroush. The consul was called in to help when a crowd of about 5,000 Iranians rushed the hotel.

The two Americans were saved by the intervention of Moslem clerics.