An Upper Darby man has been charged with first-degree murder for killing his longtime girlfriend inside their apartment and then engaging in a roving gun battle with SEPTA Transit Police officers near a busy transit hub, prosecutors said Friday.

David Savage, 45, also has been charged with four counts each of attempted murder and aggravated assault for the shooting spree early Thursday, during which investigators said he fired randomly at pedestrians outside his apartment, grazing one man in the shoulder and neck. The victim, whom authorities have not identified, was recovering from those injuries Friday, according to Delaware County District Attorney Jack Stollsteimer.

Moments earlier, Savage had shot his girlfriend, LaToya Gary, 43, in the head at point-blank range during a domestic dispute inside their bedroom, according to Stollsteimer. Gary’s mother and sister were home at the time, but told police they weren’t aware of the shooting until officers knocked at their door, according to the affidavit of probable cause for Savage’s arrest.

Gary’s mother told police she had been awakened by a noise but that Savage reassured her, saying “everything was OK,” the affidavit said. He then fled the second-floor apartment, ran outside and began shooting a handgun into the air, investigators said.

“This was a brutal, brutal murder,” Stollsteimer said, calling the shooting a “cold-blooded execution.” He added: “This is what evil looks like.”

Savage was arrested after exchanging gunfire with two SEPTA Transit Police officers stationed outside the 69th Street Transportation Center, about a block away from Savage’s apartment. Neither Savage nor the officers was struck during the confrontation.

Savage was arraigned Friday morning and denied bail because of the first-degree murder charge. It was not immediately clear if he had an attorney.

Upper Darby Police Superintendent Timothy Bernhardt and Stollsteimer commended the SEPTA Transit Police officers, calling them the “real heroes of this story” for preventing Savage from injuring more people. It was unclear why Savage turned his gun on strangers, but Bernhardt suggested that he might have been trying to “commit suicide by police” after killing his girlfriend.

Gary, a nurse’s aide who was caring for her mother, who uses a wheelchair, leaves behind two children, a 21-year-old daughter and 23-year-old son, according to her father, Matthew Gary. The shooting left him and his family reeling, especially since, from their perspective, everything seemed fine with the couple’s relationship.

The couple had been together about five years and had celebrated her birthday Monday with a trip to Atlantic City and “had a good time,” Matthew Gary said.

“I’m heartbroken and upset,” he said. “I just don’t understand how something like this could happen.”

Because of criminal convictions in New Jersey and Pennsylvania, Savage had been barred from legally possessing a gun, Bernhardt said.