The police officer who was fatally shot this week in Kansas City, Kan., was not the victim of a targeted attack against law enforcement, authorities said Wednesday.

But while the shooting did not appear to be connected to the tense atmosphere nationwide, the city’s police chief — who has now seen two officers killed in a matter of months — said he was concerned about the consequences of protests against how police use force.

“This crime does not fit the national narrative of planned attacks against law enforcement officers, but it does fit the narrative when it comes to the fact that words matter,” Terry Zeigler, the city’s police chief, told reporters at a Wednesday morning press conference. “The hate and anti-police speech has got to stop, because the consequences are real.”

Capt. Robert Melton died Tuesday, after police responded to reports of gunfire, authorities have said. Zeigler on Wednesday said Melton was shot by suspect who fired through the window of a patrol car.

The officer was pronounced dead at 2:55 p.m. local time, according to James Howard, a trauma surgeon at the University of Kansas Hospital. He was 46 years old.

“To our citizens, we will not stop fighting the good fight, each and every day for you,” Zeigler said. “Thank you for your continued support. We need it.”

Melton’s death in Kansas City pushes the total number of law enforcement officers fatally shot in the line of duty by a suspect to 31 so far this year — up from about 16 at this point last year, and ahead of the average midyear total, which is about 25, according to FBI data.

The numbers have spiked considerably this year just in recent days, with more than a third of these deaths coming in a single 12-day span.

“We do not believe that Capt. Melton’s death was a planned ambush against police,” said Mayor Mark Holland. “We believe this case is another example of a known criminal trying to escape arrest. Yet we all need to worry that the national climate may foster greater fear, and potentially inflame otherwise normal interactions and turn them into tragedies.”

On Sunday, three officers in Baton Rouge were fatally shot by a gunman, while three others were injured. The week before, two bailiffs — both deputized by the sheriff there — were killed in a Michigan courthouse, a shooting that came just days after a gunman fatally shot five police officers in Dallas.

The shooting occurred around a residential intersection about two and a half miles from the police department’s headquarters, Zeigler said.

Police initially received a call about gunshots on Tuesday afternoon, from a citizen who had spotted a burgundy colored car, Zeigler said. An officer on routine patrol saw a car that matched that description driving the wrong way.

The officer tried to stop the vehicle, but eventually ended the pursuit. The vehicle description hadn’t yet gone out to officers in the field, Zeigler noted.

After that happened, officers on patrol spotted the vehicle. The suspects tried to flee on foot, but the driver was immediately taken into custody, Zeigler said.

Melton, who was on patrol, went to help, according to Zeigler. He and another officer spotted a suspect. Melton boxed the suspect in using his patrol car, and that’s when the shooting occurred.

“The suspect produced a handgun, and fired several shots into the passenger side of Capt. Melton’s patrol car, through the window, which was halfway down,” Zeigler said. “At the time of the shooting, Capt. Melton was trying to exit his patrol car to engage the suspect.”

Zeigler said at Wednesday’s press conference that authorities believe they had taken everyone who was involved in the incident into custody, but asked members of the community to call with tips if they had information to share.

“On behalf of the men and women of the Kansas City, Kansas, police department, and the Melton family, we would like to thank our community for the outpouring of support,” Zeigler said. “We know that you share our pain.”

Two people were in custody in the aftermath of Melton’s death, though charges had not yet been filed by late Wednesday morning, police said in an email.

Investigators don’t believe anyone was hit during the initial incident involving gunfire, Zeigler said.

A police detective in this Kansas City — which is much smaller than neighboring Kansas City, Mo. — was fatally shot in May by a man police said was carjacking vehicles and had shot a driver.

This latest Kansas City shooting comes just two days after a gunman in Baton Rouge fatally shot three officers there and wounded three others in an attack that police described as a “targeted” assassination of law enforcement officers. (That gunman was from the Kansas City in Missouri, authorities said.)

Just 10 days earlier, a gunman in Dallas who killed five police officers had said he was angered by fatal police actions and wanted to kill officers, authorities said. The violence left many on edge nationwide, as police officers in many cities were ordered to patrol in pairs as a safety measure.

This story, which was first published Tuesday afternoon, has been repeatedly updated.