President Anastasio Somoza resigned early this morning, ending more than 40 years of control by his family in this Central American country.

Somoza's resignation was announced in a closed meeting of Congress by Francisco Urcuyo Maleanos, who assumed the presidency. Urcuyo, the president of the lower house of Congress, is expected to turn the government over to members of a guerrilla-backed junta early in the day.

Somoza was not present at the 1 a.m. congressional session, held in the International Hotel across the street from his bunker office. It was rumored here today that he had already left the country.

A new head of the National Guard has also been named. He is Lt. Col. Federico Mejia, former director of the police branch of the National Guard. Mejia is expected to negotiate a cease fire with leaders of the Sandinista National Liberation Front.

Somoza met Monday for the third day in a row with U.S. Ambassador Lawrence Pezzullo, apparently to discuss final details for his departure. In Costa Rica, sources close to a guerrilla-backed junta said the group plans to arrive here and take power today.

The junta's foreign minister, Miguel D'Escoto, was reported to be planning to return to Costa Rica today from meetings he conducted over the weekend with foreign ministers of the five Andean Pact countries.

He reportedly asked the Andean ministers to be present in Nicaragua at "the moment of transition" from Somoza to the junta.

In an order signed Sunday, all National Guard officers with 30 or more years of service were retired. The group numbers nearly 100 and includes all active duty generals and most colonels and lieutenant colonels.

Many are expected to leave the country with Somoza, who sources said would fly to Miami on a private jet. Most members of Somoza's Cabinet, with the known exceptions of Foreign Minister Julio Quintana and Interior Minister Antonio Mora, are believed to have left the country today.

The mass retirement apparently is part of an agreement, worked out between Somoza and the United States, to leave the National Guard in the hands of younger officers considered less directly involved with the Somoza government and to ease the way for a cease-fire with Sandinista guerrillas.

The retirement also reportedly ensures that the officers will receive government pensions in exile under an agreement with the junta. Along with the retirement order, eight National Guard colonels in high positions and on Somoza's personal staff were simultaneously promoted to brigadier general, increasing their retirement pay by approximately 75 percent.

Although Somoza had been expected to speak to the nation sometime late last night, few Nicaraguans outside his inner circle seemed aware that the 46-year Somoza family rule was quickly moving toward an end.

No public announcement was made of Somoza's plan or of the National Guard changes. Congressional representatives of the government's Liberal Party spent the day waiting to be called into session, but were clearly confused and uneasy. Most gathered in the lobby at the International Hotel, across the street from Somoza's "bunker" office, where they have been staying under heavy guard for the past several weeks.

Inside the bunker, activity was frenzied yesterday, with desks being cleared off and suitcases and trunks loaded into cars. Somoza emerged at one point and spoke to reporters.

Dressed in a light gray suit, rather than his usual casual attire, Somoza carried what he said was a Chinese-made artillery shell captured from the Sandinistas. As he crossed between buildins to the room where he normally holds press conferences, Somoza was asked when he would resign. "Not yet," he smiled, and refused to answer other questions.

Later, Somoza waved cheerfully from the back seat of a limousine that left the bunker and drove the short distance up a hill to his residence, where he reportedly met with Ambassador Pezzullo.

Few of Somoza's aides seemed as cheerful, however. Most were dressed in civilian clothes and wandered about inside the bunker waiting only to be told when they would leave.

"I don't think I'll believe this is happening until I'm in Miami," one nervous Somoza aide said.

On his door hung a suit jacket and white shirt he said were "to wear on the plane." His family, like those of most Somoza officials, left weeks ago for the United States.

"I've been in this office many years," the official said sadly. "You know, they don't live like us in the United States. I've got enough money for around six months there, but we have a style of living here . . . We are used to servants."

After six months, he said, he would see what the new government had done and maybe think about returning. "I've got my farm here," he said, "and my house. I'ii see what happens, but I want to come back."

"The young ones" in the National guard, he said, will stay.

Most of the high-ranking officers in cities still held by the National Guard have returned to Managua during the past several days as negotiations here and in Costa Rica progressed. The others, many of whom have been trained and educated in the United States are expected to lead the National Guard into a cease-fire and a negotiated integration with the Sandinistas into a new Nicaraguan army.

According to well-informed military sources here, leaders of the Sandinista army will meet soon after the transfer of power with the remaining Guard leaders. They will attempt to work out a process by which the two armies, which have bitterly fought each other for years, can be merged into a single armed force.

Early Monday afternoon, approximately 24 high-level officers entered Somoza's bunker for a private meeting with Somoza and his son, a 28-year-old National Guard lieutenant colonel. Sources said the officers were told the Guard is being "restructured to give more emphasis to youthful elements."

Somoza's concern about the future of the National Guard has been the main point of disagreement in international negotiations with the junta over the past several years. The concern has been echoed by the United States, which fears control here by a radical, all-Sandinista armed forces.

While the five-member junta apparently satisfied demands for specific outlines on what is to become of the Guard, it refused to preserve the much-hated military institution.

Although the junta has said all guardsmen involved in "crimes against the people" will be brought to trial, this is interpreted to refer to those guilty of years of repression and corruption rather than those who have merely participated in the war. But the junta clearly hopes the worst of the "old guard" will leave with Somoza.

Correspondent Terri Shaw filed this report from San Jose:

In Costa Rica, where three members of the rebel-backed junta have been meeting with special U.S. envoy William Bowdler and representatives of other countries, excitement reached a high pitch.

Junta members could not be found in their usual meeting places Monday, and rumors flew through the lobby of the Gran Hotel here about President Somoza's impending resignation and the junta's expected triumphant return to Nicaragua.

A spokesman for the junta, Manuel Espinosa, said that its members were "working out the details of Somoza's handover of power. After 45 years of dictatorship, you can't just pack your bags and go."

The three members of the junta and the 12 cabinet-level officials of the provisional government now in Costa Rica met for 3 1/2 hours Sunday night, apparently to make plans to travel to Nicaragua after Somoza's resignation.

In addition to foreign ministers of the Andean Pact nations - Peru, Ecuador, Bolivia, Colombia and Venezuela - the junta has invited the governments of Mexico, Panama, Costa Rica and the Dominician Republic to send representatives to observe the transfer of power.

Two prominent Nicaraguans have also been invited to accompany the junta. They are the Archbishop of Managua, Miguel Obando y Bravo, and the head of the Nicaraguan Red Cross, Ismail Reyes.

Junta spokesman Espinosa said the Andean Pact nations would play a key role in arranging the transfer of power in Nicaragua. He said the five foreign minister would meet with the Nicaraguan junta either here or in Nicaragua when a political settlement is reached.

Espinosa said the junta has proposed the following scenario for the transfer of power:

Somoza gives his resignation to the Nicaraguan congress which then appoints an interim persident.

The junta and other provisional government officials travel to Nicaragua and formally assume power.

Members of the Organization of American States who participated in the negotiations to obtain Somoza's departure formally recognize the new government. CAPTION: Picture, Nicaraguan President Anastasio Somoza displays missile used by rebel forces. UPI