“Anyone who knew her knew that she loved her family and she loved her friends,” her daughter Genesis said. “And that’s not only her blood-related family but also her blue family as well. My mom loved being a cop she loved every part of it.”

A mural depicting Familia was unveiled in 2019. It was specifically placed on the side of the precinct to watch over and “smile down” on the officers stationed there.

On a corner in the Bronx strained by steady rancor over unsolved crimes, and distrust of the police, Officer Miosotis Familia was a balm.

[Related: 2 police officers shot and killed in McAllen, Texas.]

She had earned a reputation as “a good policewoman” in the short time she was assigned to an R.V.-style police command post at East 183rd Street and Morris Avenue, two miles north of Yankee Stadium, a longtime resident, Roma Martinez, said. She waved hello; she spoke Spanish.

But long before she arrived, a hostility toward law enforcement personnel was building in Alexander Bonds, who had been in and out of prisons and jails for 15 years and was slipping into severe mental illness. Last year he warned in a Facebook video that he would not back down if he encountered police officers on the streets: “I got broken ribs for a reason, son. We gonna shake.”

About three hours later, with Fourth of July fireworks still going off, Mr. Bonds strode up to Officer Familia’s command post and fired a .38-caliber revolver through a window, killing her with a bullet to the head. She was the first female New York Police Department officer killed in the line of duty since the Sept. 11 attacks, and only the third female officer killed in a combat-type encounter in the department’s history.

The New York City police commissioner, James P. O’Neill, said in a message to officers that she was “assassinated without warning, without provocation, in a direct attack on police officers assigned to safeguard the people of New York City.” And once again the city was plunged into mourning over a targeted police killing that appeared to result in part from a swirl of mental illness and anger at the police, two and a half years after a man with a similar history fatally shot two officers through their patrol car windows.

In the command post around 12:30 a.m., Officer Familia’s partner, Vincent Maher, pleaded for help over the radio: “My partner’s shot! My partner’s shot!” His call drew scores of officers and turned stretches of Independence Day festivities into a crime scene.

Officers chased Mr. Bonds, 34, who wore a black hooded sweatshirt, black pants, black sneakers and black gloves. When they confronted him, he pointed his five-shot Ruger revolver at them and fired, a preliminary investigation indicates. The officers — a sergeant and a patrol officer — shot him dead. A bystander struck during the shootout was in stable condition.