In September, when Sandinista guerrillas retreated from their ill-fated attempt to overthrow President Anastasio Somoza after a month of civil war, there was little doubt that peace in Nicaragua was only temporary.

Throughout the winter and into spring, the country waited tensely for the next rebel assault. When it finally began May 28, it was far bigger and far better organized than most observers - apparently including Somoza - had dreamed.

Nearly a month later, the Sandinistas have Somoza on the run. Some of the nation's principal cities, including Leon and Masaya, are controlled by rebels. Others are in flames as battles continue between the rebels and Somoza's National Guard.

While he desperately bombs and burns his own country in the hope that more guerrillas than civilians will die, Somoza rapidly is losing the support, or tacit legitimacy, long accorded him by the rest of the world.

The transition of the leftist Sandinista National Liberation Front from a small, poorly armed guerrilla group to a full-fledged rebel army with logistical, material and diplomatic support was no accident. It involved the effort during recent months of the thousands of Nicaraguans, from guerrilla military leaders to impoverished peasants and businessmen and sympathetic foreign governments.

When the first round of fighting ended in September, the United States, the Dominican Republic and Guatemala, under the auspices of the Organization of American States, began a mediation effort aimed at resolving the Nicaraguan crisis by arranging a government that included neither Somoza nor the Sandinistas. Although that unsuccessful effort dragged on until January, the Sandinistas denounced it soon after it began and went their separate way to prepare for war.

Although the Sandinistas lost September's battles, they won thousands of new recruits from Nicaraguan youths who had helped hold their barricades. At hidden camps in northern Costa Rica, southern Honduras and inside Nicaragua, the core of experienced guerrillas trained the youths for combat.

They were joined by brigades of volunteers from other Latin American nations, including a group of 80 Panamanians led by a high-ranking former member of that country's government. Individuals from as far away as Chile and Argentina traveled to the rebel camps to join what was the only going revolution in Latin America.

On the diplomatic front, the Group of 12, a organization of prominent Nicaraguans publicly backing the guerrillas, traveled the Western Hemisphere and sought support. With funds garnered in Nicaraguan bank robberies they bought arms. Arms were also collected by international solidarity groups and reportedly given by the governments of Venezuela and Panama. According to Somoza, they were also donated by Cuba.

While Somoza beefed up his armed forces and warned the rest of the world that the Sandinistas planned to establish a Communist beachhead in Central America, the Group of 12 attempted to soothe international fears by talking about human rights and the end of the Somoza dictatorship.

The group, whose members are well-spoken and well-dressed and included two priests, several academics and a few of Nicaragua's ricest citizens was often well received.

Within Nicaragua, the United Peoples Movement sprung into action. Formed last summer by student and labor groups allied with Sandinistas of the Proletarian faction, one of three guerilla subgroups, the Movement organized urban and slum cadres to plan political and offensive strategy for true war.

Within Nicaragua's urban slums, the Movement trained those youths who had stayed behind to build barricades and handle weapons. At night, when the National Guard feared to enter the slums, the Movement held classes in politics and civil defense. Refugee centers were designated and food and medicine were stockpiled.

By early winter, it was clear the U.S.-led mediation effort would fail. One by one, groups dropped out of the Board Opposition Front a coalition of politically moderate anti-Somoza organizations chosen by the United States to represent the non-guerilla opposition at the mediation talks.

On February 1, the Movement, the Group of 12 and some of the Broad Front dropouts, joined to form what they called the National Patriotic Front, the political arm of the Sandinistas. Its program called for the overthrow of Somoza, the formation of a new army and political self-determination in Nicaragua.

By April, the Sandinistas were ready to begin a series of dry runs to give their new troops a taste of combat. The results were not encouraging. During Easter week, an attempt to take over the National Guard garrison in the Northern city of Esteli failed.

In small scale attacks in several cities, a number of individual government officials and informants were assassinated but there were also heavey guerrilla casualties.

The setbacks delayed the beginning of all-out war until May 28, when at least 300 Sandinista troops crossed into Nicaragua from Costa Rica and declared that the revolution had begun.

On June 4, a Sandinista-called general strike paralyzed the country. Two days later, Somoza declared martial law.

Supported by citizens in the slums and Movement-organized militias who built and defended barricades, the rebels rose in Leon, Esteli, Matagalpa Masaya and other smaller towns.

A rebel column moved in from the north and on June 9, Managua came under attack.

For nearly two weeks, the battle moved up and down. While the Sandinista arsenal was far superior to last September, it was still not match for the heavy artillery and aircraft of the government. The southern offensive was defeated and limped back to Costa Rica.

But Sandinista strategy was to spread the Guard thin, to take advantage of its need for long supply lines and ponderous troop movements and its dislike for street fighting. Convoys were ambushed, and Natural Guard soldiers fighting from city garrisons were surrounded and cut off from reinforcements.

Somoza has 15 to 20 combat aircraft capable of heavy damage in this small county of adobe houses and wooden shacks. But even the airplanes could not cover half a dozen widespread fronts at once and, as international support for his government dwindled, Somoza could not find more to buy.

In recent days, the Sanistas have won more battles than they have lost.

Leon Masaya and the southern town of Diriamba are in rebel hands. Large portions of Esteli, Matagalpa and Chinandega are occupied by the Sandistas. After heavy combat, the guerrillas retreated from western Managua, and a zone measuring several square miles controlled by the rebels in the eastern part of the city is under heavy government bombardment.

In the south, a second invading force launched June 15 has failed to advance more than a few miles into Nicaragua.

Saturday, 17 members of the Organization of American States called for Somoza's immediate resignation. Four Latin American countries have already broken relations with his government.

It has become increasingly probably that, sooner or later, Somoza will go.

The question then becomes what kind of government will replace him. The Sandinistas have appointed a five-member provisional junta to take over, but few of those 17 OAS member governments have indicated their public support for its installation.

A number of OAS members who fear the guerrillas' leftist politics, including the United States, do not want a Sandinista-controlled government in Nicaragua.

While the junta membership covers a range of left-of-center political beliefs, it excludes a numer of important moderate groups. Among them are the Conservative Party, Nicaragua's traditional opposition to Somoza, and opposition splinters of Somoza's own Liberal Party.

Following a pact in March that united the three bickering Sandinista factions under a banner of ousting Somoza and establishing democracy, the guerillas have said very little specifically about politics.

While leaders of two of the factions profess a Marxist philosophy adapted to Nicaraguan needs, and all three believe some sort of socialism is the best long-range future for the country, the united Sandinistas agree that Nicaraguans first need a chance to live in democratic peace. They say they would support free elections.

Some of their leaders, however, acknowledge that there is a split below the surface.

"Some day, when this all over, we may be fighting among ourselves," one guerrilla said. "It's not the majority, but some of us will not be able to put down our guns."

For now, however, most Nicaraguans seem willing to support the Sandinistas at least until Somoza is gone. No future, they apparently believe, could be as bad as the past.