A Salvadoran soldier patrols a neighborhood in the country as part of new widespread security measures to curb violence. ( Salvador Melendez /AP)

After becoming the world’s murder capital last year and posting an equally bloody start to 2016, this ­violence-torn Central American nation has seen its monthly homicide rate fall by about half.

The government attributes the drop to a tough military counteroffensive against the country’s powerful gangs, deploying a special security force and transferring imprisoned ­organized-crime leaders to a maximum-security lockup to isolate them.

But the gangs also claim credit. The three main groups — the Mara Salvatrucha, Barrio 18 Revolucionarios and Barrio 18 Sureños — forged a nonaggression pact in March to try to reduce the killings. In a joint video message, they said their aim was to convince the government that the crackdown was unnecessary.

Either way, killings in El Salvador dropped from 611 in March to 353 in April and 351 in May. There were 331 homicides in June, compared with 677 in the same month in 2015.

Last year the country recorded more than 100 killings per 100,000 residents. That rate was so high that even if it is halved for 2016, El Salvador would still be firmly in the top 10 for killings for any country not at open war, though it’s a fraction of the deaths seen in a war zone such as Syria, where casualty estimates have run into the hundreds of thousands since 2011.

Authorities say most of El Salvador’s dead are gang members slain in encounters with security forces or by rivals on the streets and inside prisons.

“The reduction in homicides is due to the effectiveness of the plans by police and the extraordinary measures by the government, especially inside prisons,” national police chief Howard Cotto said last week.

Authorities say isolating jailed gang leaders makes it harder for them to issue orders to their underlings out on the streets.

“We have gradually been bringing the penitentiary system under control, and we are going to finish the job,” Vice President Óscar Ortiz said recently.

The gangs see things differently. A senior member of one, the Barrio 18 Sureños, told the Associated Press the killings have fallen because gang leaders ordered their street soldiers to stand down.

“When we have wanted war, we have waged war on them, and right now we are not thinking that way,” the gang member said, speaking on the condition of anonymity to avoid being targeted by authorities. “We want things to be solved in a different way.”

He said he is part of a team that coordinates among the three big criminal bands, and all are open to dialogue and have agreed to maintain a cease-fire.

Experts say the government crackdown and the gang truce have probably both played a part in reducing homicides.

José Miguel Cruz, a specialist on Salvadoran organized crime at Florida International University, said the fact that the gangs are behaving less aggressively may suggest only that they are trying to keep a lower profile, not that the government has won the battle. He also worries that the lull in violence could be fleeting.

“I fear that this is temporary,” Cruz said. “That it is going to last until the gangs figure out another way to confront the government.”

When President Salvador Sánchez Cerén took office in 2014, he established a policy of confrontation with the gangs. A former guerrilla, Sánchez Cerén doubled down on that approach in March after gang members used guns and machetes to slaughter 11 people in the town of San Juan Opico, outside the capital — an attack whose brutality was shocking even for Salvadorans numbed by daily reports of death and mayhem.

Within weeks of the Opico massacre, Salvadoran lawmakers approved legislation that included isolating gang prisoners and deploying 1,000 soldiers and police to pursue and dismantle the gangs. The government has “recovered the hope that this country is now on the path to defeat crime,” Sánchez Cerén said in mid-May.

The three gangs have called a truce before, in 2012, which allegedly was facilitated by then-President Mauricio Funes’s government.

Funes’s administration has denied being the architect of that pact. However, an official in his government, who says he was involved in its planning and implementation, says that the truce was a matter of government policy and that the former president and security cabinet approved a strategy allowing mediators to negotiate with gang representatives inside and outside prisons. He spoke on the condition of anonymity to avoid drawing the attention of investigators in an ongoing probe.

Funes did not respond to an email request for comment. On a recent radio show, he said his government didn’t design the treaty and only “facilitated the pact” the gangs had established.

The attorney general’s office on May 3 ordered the arrest of 21 people allegedly involved in negotiating the truce, including former mid-level officials. Prosecutors said they were suspected of crimes such as introducing illegal items into prisons and illicit association in their contact with gang members.

The idea of negotiating with the gangs is widely unpopular among Salvadorans. A recent poll by the newspaper Diario de Hoy found that 78 percent of respondents would oppose another truce, compared with 10 percent who would support one. The May 20-24 survey polled 2,174 adults and had a margin of error of 1.5 percentage points.

“I don’t believe in the truce,” said San Salvador resident María Teresa Perdomo, who called the 2012 pact a farce because even while it was in effect, the gangs “kept on killing and extorting people.”

Street vendor José Melgar agreed, saying the government needs to take a tough line on the gangs.

“You have to hit them hard,” he said. “They are bad, they were born bad, and they don’t spare anyone.”

— Associated Press