National Guard troops battled Sandinista guerrillas in many of Managua's slum and middle-class neigborhoods this morning, while the government launched a major counteroffensive against the rebels in Masaya.

Later in the afternoon, the government claimed that the guerrillas had been drived off from the southern near the Costa Rican border, where two weeks ago the sandinistas began what they said was their final offensive against President Anastasio Somoza.

The announcement said that "the mission was concluded at 9 this morning" and that 48 "communist mercenary invaders" had been killed in the final battle. The government had placed the strength of the original invasion force of 300.

Another National Guard communique claimed that the small northern city of Ocotal, which guerrilla columns invaded Wednesday, had been recaptured.

What has become regular nighttime fire-fights in and around this capital city greatly increased in intensity last night. Steady automatic weapons fire was punctuated by bombs, armored car cannons and the sound of jets strafing guerrilla positions.

The battles in several neighborhoods continued until midmorning, when the guerrillas took flight. Government troops moved up the streets and began calling the citizenry to tear down Sandinista barricades.

Early this morning government aircraft began strafing Masaya, where the guerrillas have had the National Guard garrison under siege for several days. Guard reinforcements arrived at the city late yesterday afternoon.

Radio Sandino, the clandestine guerrilla station, claimed that the Masaya garrison had fallen, but there was no confirmation. Heavy fighting throughout the day prohibited entry into the city beyond a few blocks.

Refugees leaving Masaya on foot, carrying white flags and bundles of belongings, pleaded for International Red Cross intervention to evacuate civilians.

[In Washington, the State Department said the United States is "actively considering" evacuating about 50 dependents of American diplomats, most of whom live in the Managua area.]

Two weeks after beginning their offensive, the Sandinistas have managed to occupy far more territory than was anticipated. Yet there is a general feeling here that the far better-armed National Guard has not yet unleashed its full firepower on the rebels.

Foreign Minister Julio Quintana maintained today that, as long as the guerrillas do not control the Guard garrisons in the cities they have invaded, those cities are not technically "occupied".

While the guerrillas now control nearly all of Leon, Nicaragua's second-largest city 54 miles north of here, and have set up what amounts to a provisional municipal government there, the large Guard garrison is still reportedly under siege.

The Guard now claims to have Leon surrounded, but has given no reason for delaying a counteroffensive.

The skirmishes in and around Managua appeared to be part of Scandinista strategy both to demoralize the National Guard and to mobilize the population for a future battle.

The layout of the capital itself, unlike other Nicaraguan cities, makes a direct assualt nearly impossible. Managua's entire downtown area was destroyed in a 1972 earthquake and never rebuilt. Today the city is a series of self-contained neighborhoods, divided by hills and brush prairies, spread over an area of several miles.

Since a month-long outbreak of civil war last September, many of the lower-income neighborhoods have been scenes of nightly fire-fights between local rebels youths and the National Guard.

In the meantime, civil defense committees organized by Sandihistas and guerrilla sympathizers within the "barrios," or districts, have prepared refugee stations and collected stores of food and medicine for an anticipated battle.

In one barrio several miles from central Managua, the local committee has organized its own information service, with daily mimeographed accounts of Radio Sandino news. Last weekend, a source there said, guerrilla "outsiders" entered the area and began mobilizing already-trained cadres of youths inside. Residents were told, the source said, to prepare themselves for battle this weekend.

Last night's barrio fights began at around 7:30 p.m. According to residents of Luis Somoza, a poor neighborhood named after the president's late brother, masked local youths and outsiders in guerrilla uniforms took to the streets as night fell, yelling Sandinista slogans and calling on the residents for support.

The Guard entered shortly afterward in jeeps equipped with heavy machine guns and residents pulled inside their homes behind the brick barricades many have built in front of their windows.

This morning, that neighborhood, plus the eastern barrios of La Nicaragua and Las Americas, near the international airport, were the scenes of intense fire-fights.

The guerrillas abandoned the neighborhoods around noon, and in the first day of bright sunshine following a week of rain, residents came out into the street to exchange stories and food.

As a week-long general strike against Somoza continues, many of Nicaragua's poorer residents are without food, or money to buy what is available. Near riots broke out this afternoon in Managua's central market, where local residents complained that merchants had doubled or tripled their prices.

A fire began in one group of stalls, bringing police who shot and wounded two youths who allegedly ran after being caught rummaging for shoes among the smoldering rubble.

After the youths had been taken away, the police retreated and scores of people began picking through the ruins for spoils.

This afternoon, the charred chassis of an automobile lay on its side in the middle of the barrio's main street as residents wandered up and down looking for food.

Mercedes Martinez, a 46-year-old woman who lives with her two sons in a small adobe house, described nights in which local people huddled on the floors of their homes to escape the shooting. "For me the nights are a horror," she said.

Martinez and many others in San Judas, a working-class area where most people have been out of work for weeks and some for months, described regular house-to-house government searches after nights of heavy fighting in which youths were carried away, "We never see them again," she said.

While all those interviewed in the neighborhood said they wanted the Somoza government to fall, they wanted above all for the fighting to stop. Asked about their own politics, many said they knew nothing about "those things."

As she talked, Martinez started to cry. "Only God can help us now," she said. "We are at the end. We have no food now, we have no clothes. Would you please someone here to help us?" CAPTION: Picture, A Nicaraguan family flees the town of Matagalpa Friday, carrying a white flag. AP