SAN SALVADOR — They had faced off many times before, on the streets, with guns in their hands. But when top leaders of two of the hemisphere’s most violent street gangs sat across from one another in the stifling air of a maximum security prison here this year, the encounter had a very different aim: peace.


With a military chaplain and a former lawmaker officiating, the imprisoned gang leaders held a moment of silence for the thousands of people their street armies had killed. After a few more meetings — and the government’s concession to transfer 30 of the leaders to less-restrictive conditions — they shook hands on a pact to put an end to the killings.


“We said we have to talk because things are getting out of hand,” said Carlos Tiberio Valladares, a leader serving time for murder who has tattoos of his gang etched across his face. “No one is going to tell you they want their kids to continue on this path.”


Five months later, the truce endures in El Salvador, long one of the most violent countries in the Americas. With 30,000 to 50,000 members and weaponry that includes assault-style rifles and grenades, the two gangs are virtual armies that have the power to affect the security of the entire region — and they have used it to terrorize populations still weary from years of civil war and instability.


Now the truce is moving this country in the opposite direction, the authorities contend, leading to a precipitous drop in violence. But others question whether the government should have essentially made what some consider a pact with the devil for the public good.


“This is a historic moment in El Salvador,” said Alex Sanchez, a former Salvadoran gang member who directs Homies Unidos, an antiviolence program in Los Angeles. “If we lose this moment, we lose the moment of a lifetime.”


Homicides in this country of six million people are down 32 percent in the first half of this year; kidnappings have fallen 50 percent; and extortion has declined nearly 10 percent, according to the Salvadoran security ministry, which attributes the drop largely to the truce.


The peace talks involved the region’s two largest gangs, Mara Salvatrucha and Barrio 18, which trace their roots to Los Angeles. Their ranks mushroomed in the United States after young men fled Central America’s civil strife in the 1980s. When many were later deported for crimes in the United States, the gangs formed large affiliates in El Salvador and neighboring countries.


In a string of attacks two years ago that killed more than 16 people, gang members held up passengers on city buses and burned one bus while it was filled with riders. One of the gang leaders brokering the truce was part of a gang that kidnapped and killed the young son of a businessman. Some gang members have served as foot soldiers for drug trafficking organizations based in Mexico.


At the first truce meeting, hot stares fed the tension, according to those present. About 200 soldiers stood nearby in case the sit-down dissolved into bloodshed and ignited the thousands of gang members that the leaders command from behind prison walls.


These prisoners, some branded head to toe with gang tattoos, now speak of a new day. They raise the prospect of working instead of stealing to make ends meet. They liken the truce, however fragile, to the peace accords that halted the 12-year civil war here in 1992.


“We have shown good will,” said Victor Antonio García, a Barrio 18 leader deported from Los Angeles. “But now the government has to get involved. We need, like, an affirmative action law here for gang members who quit and need jobs.”


The truce has made for some head-spinning moments.


Gang leaders sat down last month with José Miguel Insulza, the secretary general of the Organization of American States, who, as if at a summit meeting of regional leaders, called the truce a promising turn in stemming the tide of violence in Central America. Later, six masked men symbolically laid down high-powered weapons at his feet.


“If the presence of the O.A.S. secretary general helps in this peace proposal, I will be here,” Mr. Insulza said.


Many remain skeptical that the truce will stick, noting the lack of alternatives for young men in poor neighborhoods. After a sizable drop, the number of homicides rose again early this month, and reports of extortion and disappearances remain high, leading the chief medical examiner to warn that the pact “may be in danger of fracturing.”