QUILALI, Nicaragua (AP) _ Former Contra rebels released 20 hostages Sunday in return for a promise that they would go unpunished, hours after leftists holding Nicaragua's vice president and other officials took more captives.

The former Contras said they would release their remaining 21 hostages ''in the next few hours,'' said Francisco Mayorga, leader of a government delegation mediating the crisis in this northern Nicaraguan town.

The former Contras dropped their demands for the removal of Sandinista officials from top government posts, and the government also promised to study demands for land and aid. Earlier in the day, they had rejected a proposal for simultaneous release of all captives.

Before the agreement was announced, the pro-Sandinista gunmen in Managua allowed the release of two hostages, Jorge Ramirez and Guillermo Selva, a member of the country's Supreme Electoral Council.

The releases could be a breakthrough in the hostage crisis that threatened to rekindle the devastating civil war between U.S.-backed Contras and leftist Sandinistas in the 1980s.

Rebels from both sides in the war have become angry with the government of President Violeta Chamorro for failing to deliver land, money and other concessions promised after a peace accord was reached. The hostage crisis is the second uprising by rearmed rebels in as many months.

The crisis began Thursday when the Contras seized members of a government commission traveling in the area to discuss a government amnesty for the rearmed rebels.

Leftists loyal to the former Sandinista government then retaliated by taking 20 officials - including Vice President Virgilio Godoy - hostage in Managua. On Sunday, they also apprehended nine Nicaraguan journalists.

The pro-Sandinista militiamen, led by former Sandinista army Cmdr. Donald Mendoza, said Friday that they wouldn't release their captives until the former Contras released theirs.

At one point in Managua on Sunday, the edgy leftist gunmen shot indiscriminately for 20 minutes from within the house where they were holding the hostages, positioning underwear-clad captives in the windows. No one was injured.

In Managua, a gunman who did not identify himself told pro-Sandinista Radio Ya that the journalists were seized for identifying the name of their commander in published and broadcast reports.

''The journalists are now hostages,'' declared the gunman, one of about 20 heavily armed men who raided the headquarters of the center-right National Opposition Union on Friday, seizing 34 hostages.

The journalists - all from Nicaraguan news outlets - had been inside the house for hours. Other reporters were expelled Sunday morning.

Hours later, the gunfire erupted after the hostage-takers became alarmed when a group of reporters broke through a police cordon around the site, police said.

One of the journalist-hostages described the shooting in a live broadcast pocked by the sound of AK-47 gunfire.

''Alfredo Cesar, the former president of the National Assembly, and two other hostages have been positioned in the windows in their underwear,'' said Omar Garcia of the pro-Sandinista Radio Ya. He said he spoke from the floor.

On Saturday, the pro-Sandinista rebels freed 14 of their hostages, including two ailing politicians.

The gunman also said the commandos on Sunday had expelled a monitor of the national Human Rights Commission, Ignacio Diaz Brenes, saying he had ''acted as a spy'' for authorities. The gunman did not elaborate.

Hundreds of heavily armed police sealed off the area, placing huge steel barricades on streets and metal spikes on the roads.

The agreement by the rightists to release their captives came after Mayorga's delegation came to Quilali with a proposal for the immediate release of all hostages on both sides and for the escape of the abductors unpunished.

The proposal, announced Saturday, was endorsed by Mrs. Chamorro, conservative opposition leaders and Sandinistas led by former President Daniel Ortega.

Contra leaders initially issued a statement, read on Radio Ya, saying Jose Angel ''The Jackal'' Talavera and his 400 rearmed Contras ''refused to meet with the commission sent by the government.''

Later, the rebels met with the delegation, and their leader agreed to give up his demands for the firing of Defense Minister Gen. Humberto Ortega and presidential chief of staff Antonio Lacayo, the report said.

Contras are angry that Sandinistas retain key positions in the government despite their electoral defeat by Chamorro's center-right coalition in 1990.

Chamorro's economic program, including massive cuts in public spending, made inflation drop from 33,000 percent in 1990 to 3.5 percent last year. Unemployment the past three years has soared to 60 percent.

An estimated 1,400 former rightist Contras and some demobilized Sandinistas have rearmed in recent months. At least 50 people were killed last month in a rebellion in Esteli, about 60 miles north of Managua.