A month before the Mexican photojournalist Rubén Espinosa was murdered in Mexico City in late July, the governor of Veracruz, the province Mr. Espinosa had fled fearing for his life, gave other journalists a warning.

“Behave,” Javier Duarte, the governor of Veracruz, urged reporters. “We’re going to shake the tree and a lot of rotten apples will fall.”

Mr. Duarte said that his warning was meant to deter journalists who are sympathetic to drug traffickers and other criminals. But many Mexican journalists understandably saw it as a threat to journalists who produce critical coverage of local officials.

Since 2010, at least 41 journalists have been killed in Mexico. Roughly 20 have disappeared. Mexican journalists are targeted by powerful criminal organizations and in some instances by government officials who don’t want their misdeeds exposed. The majority of cases remain unsolved, leaving journalists in many parts of the country with a terrible choice: they censor themselves or get silenced by a bullet.

The government of President Enrique Peña Nieto has not done enough to protect journalists or fight this culture of impunity.

“An attempt on the life of a journalist is an attack on society’s very right to be informed,” a group of prominent journalists and press advocates wrote in a letter to Mr. Peña Nieto, expressing outrage over the latest killing.

They demanded that his administration carry out a credible investigation into the slaying of Mr. Espinosa, a 31-year-old photojournalist, and examine the involvement of local officials who may have been complicit in the killing of journalists.

Crimes against journalists are not the only ones that routinely go unpunished in Mexico. The country’s criminal justice system is notoriously weak, susceptible to political meddling and corruption. This is most acute in parts of the country wracked by violence fueled by the drug trade. The authorities were deeply embarrassed last month when the country’s highest profile prisoner, the drug kingpin Joaquín Guzmán Loera, escaped from prison for the second time.

Mr. Espinosa left Veracruz, a southeast coastal state, shortly after he photographed student activists who were beaten by masked men. When he arrived in Mexico City, he told friends he felt unsafe because strangers had asked him if he was the photographer who had fled Veracruz. Mr. Espinosa was shot in a friend’s apartment on July 31, along with four women. Prosecutors detained a suspect and have sought to portray the crime as a robbery, but many Mexicans find that account dubious.

Since Mr. Duarte assumed office in 2010, intimidation and crimes against journalists in Veracruz have soared, according to press freedom advocates. Fourteen have been killed and at least three have disappeared. In most cases, local officials have tried to play down the idea that the journalists were murdered to silence them.

Ending these assaults on the press requires forceful action by Mr. Peña Nieto. He should repudiate Mr. Duarte’s warning — the two men belong to the same party. And beyond investigating and prosecuting past crimes, he and local officials must take concrete steps to protect journalists who risk their lives doing their jobs.