About 20 leftist guerrillas shot their way into the National Palace yesterday and seized about 50 senators and other officials as hostages.

At least three persons were reported killed in the firing before National Guard troops surrounded the palace and the nearby National Cathedral, also held by the guerrillas. One of the dead was a guardsman and another was a lottery ticket salesman apparently caught in the crossfire.

The Red Cross said a caller from inside the palace reported at least 15 persons were wounded in the takeover. The building also houses several ministries and at least two Cabinet members were believed to be among the hostages.

A cease-fire was declared almost an hour after the initial shooting and Managuan Archbishop Miguel Obando Bravo entered the palace to begin negotiations at the request of the guerrillas - members of the Sandinista National Liberation Front that is dedicated to toppling the government of President Anastasio Somoza.

The Somoza dynasty has ruled this Central American nation of 24 million people since 1937, until recently with strong U.S. support.

Archbishop Obando who has mediated between the guerrillas and the government in the past, carried the Sandinistas' demands to Somoza's office. They reportedly asked $10 million ransom, freedom for all political prisoners and a plane to fly them to Cuba.

Opposition sources say there are about 130 political prisoners in Nicaragua, which has been widely denounced by human rights groups for alleged repressive policies. The Carter administration has pressured Somoza to liberalize, and President Carter recently wrote him a letter congratulating him on recent changes.

The guerrillas lined up the hostages along the large windows of the building to ward off fire from the national guard, witnesses said.

Somoza went on military radio to announce that the wounded were going to be evacuated and ordered his troops, "under no circumstance is anyone to open fire. This is understood."

Military officials said the raiders managed to penetrate the heavy security by wearing uniforms similar to those worn by the National Guard, Nicaragua's combined army police. They said as soon as invaders were in the building they ran through the corridors shooting and some palace guards were among the wounded.

Witnesses reported there was a raging gunfight as troopers charged into the building at the first sound of shots and engaged the guerrillas.

More than 100 national guardsmen set up a security cordon for blocks around the palace and barred anyone from entering the area. Military helicopters hovered over the palace, with the occupants occasionally firing into the building.ith the occupants occasionally firing into the building.