Investigators do not think that a man who opened fire Thursday night on four police officers with an AR-15-style weapon in Baltimore had staged an ambush, as initially feared, the police commissioner said at a news conference Friday.

But the commissioner, Kevin Davis, repeatedly pointed out the dangers of the semiautomatic gun, which police displayed for reporters, and which he said fired .223- caliber bullets capable of piercing the protective vests worn by patrol officers.

Davis described the gunman, who was fatally shot by police, as a repeat violent offender who “was somehow able to get a rifle like that.” He lamented that “there are guns like this all over the place” and that as the nation’s “conversation on guns drags on, we’re lucky we don’t have four dead cops today.”

Davis said authorities are working to trace the gun’s origin and determine how the shooter obtained it. But he said it seems the gun was assembled from parts taken from other weapons and that identifying a manufacturer might be impossible. He described the weapon as a rifle with a pistol-grip handle; it has also been described it as a long pistol.

[Police say gunman opened fire on officers with AR-15 style weapon]

What Davis said he is sure of is that “it is a firearm that is out on the streets of Baltimore. It shouldn’t be. . . . These weapons are designed to kill.”

Police identified the gunman as Dayten E. Harper, 33. Authorities said he lives near the apartment complex in West Baltimore where the attack occurred. Court records show he has been convicted in Maryland of armed carjacking and assault and has numerous other arrests, including one for attempted murder that was dropped by prosecutors.

The shooting in Baltimore occurred one week after a sniper in Dallas killed five police officers and injured nine others, and on the same day that federal authorities warned law enforcement agencies in Maryland about credible threats from gangs about killing police.

Davis said no evidence has surfaced that Thursday night’s assailant was connected to that threat or that he tried to lure officers to the apartment complex to shoot them. Officers turned into the parking lot because they heard gunshots, Davis said, and came under fire.

“They went toward trouble and they were met by a gunman who turned the firearm . . . on them,” Davis said. But the commissioner said recent mass shootings and the targeting of police in Dallas makes this “a unique time, a challenging time.” He said not every incident “fits into that national discussion, and we don’t believe last night’s did. . . . There was a guy outside shooting a gun. Officers heard the gunfire, and they went to investigate. They were fired on by a bad guy. That’s not the first time that’s happened in Baltimore.”

But Davis said the motive remains a mystery, and police are not sure whether Harper was shooting at someone else as officers arrived.

The incident began shortly before 9:30 p.m., when four officers dressed in plain clothes sitting inside an unmarked Nissan Altima heard gunshots while driving in the 2300 block of Winchester Street. They were all wearing protective vests that said “police” and badges.

When they pulled into the parking lot of an apartment complex, Davis said, they saw a man shooting with the AR-15-style rifle. Davis said the man turned toward the officers in the vehicle and opened fire from about 50 yards away.

All four officers got out and two — veterans of 16 and six years — returned fire. Police said that Harper, thought to be wounded, ran through an open area of the apartment building and threw the weapon into some trees. He then went to a second-floor landing.

At least two officers found him on the landing and began treating him for a bullet wound to his upper body, police said. But Davis described those initial moments as chaotic, with reports broadcast over police radios of a possible second gunman inside the complex.

The officers and the wounded Harper were trapped on the second-floor landing for about 90 minutes while tactical officers secured the building. A police spokesman said the officers treated Harper but couldn’t move from their position, and paramedics could not go to them.

“It remained a hot, active scene,” Davis said. “Those long guns have the power to reach out and touch someone from a long, long distance.” No other shooter was found, and about 11 p.m., officials got Harper into an ambulance and took him to a hospital, where he died.

“We don’t know why he shot at us,” Davis said, “but we know how it makes us feel. Angry. Sad. Bewildered.”

He said that residents had offered support all day Friday: “They want to us to know they have our back.”