(CNN) Baltimore police on Thursday defended the shooting a day before of a 13-year-old carrying a replica gun, saying authorities had little option but to pursue the boy when they saw him walking down the street with what looked like a deadly handgun.

"I would argue our police officers were compelled to act when they saw that 13-year-old with a gun in his hand," Baltimore Police Commissioner Kevin Davis told reporters.

Two plainclothes detectives, one male and one female, were returning from a strategy session on how to deal with a recent spate of gun violence when they spotted the teen walking down the street, Davis said.

They identified themselves and ordered him to drop the gun, but the boy ran for about 150 yards with the officers in pursuit, Davis said.

A witness interviewed by both CNN affiliate WBAL-TV and by the police said the boy turned back toward the officers with the gun in his hands before he was shot.

"I heard him yell, 'It's not real,' like twice, and that quick, the male officer shot him twice in the leg," said the man, whom the station identified only as Bryan.

One of the two officers, a 12-year-veteran named Thomas Smith, shot the teenager twice, once in the leg and once in the shoulder, according to Davis.

The teen is expected to recover from his injuries, police said.

according to Davis. What police at first thought could have been a gun turned out to be a Daisy Powerline 340 .177-caliber BB gun. The weapon is meant to be used for target shooting,

Davis called the weapon "a dead-on ringer for a Beretta 92FS semiautomatic pistol."

Davis said he did not know why the teenager had the BB gun or why he ran. He said officers had interviewed the teen's mother and that she knew he had left the house with the gun.

He defended the officers' actions, saying officers couldn't have known the gun was a replica.

"They did what the community expects them to do," he said.

Police can't just watch someone "walk down the street in broad daylight anywhere in Baltimore with what looks like to be a semiautomatic pistol in his hand," Davis said. "We can't call 911, we are 911."

Officers, he said, had no idea what the teen's intentions were.

Photos: A city tries to come together Photos: A city tries to come together A year after protests shook Baltimore, the city is searching for a new mayor and unity. A woman lights a candle at a vigil marking the anniversary of the protests, which erupted after the death of a young black man in police custody. Hide Caption 1 of 10 Photos: A city tries to come together Protesters gather at the corner of Pennsylvania and North Avenue to commemorate the one-year anniversary of the riots. That corner, which was the epicenter of the unrest, is the nerve center of West Baltimore. Hide Caption 2 of 10 Photos: A city tries to come together The old Pemco porcelain-enameling factory in Bayview has been vacant for nearly a decade. Once an important industrial hub, Baltimore saw many companies depart for cheaper labor in the South or abroad.



Hide Caption 3 of 10 Photos: A city tries to come together A man serves raw oysters in Baltimore's famous Lexington Market. In recent years the city has invested heavily in tourism, hoping to attract external dollars to the city. Hide Caption 4 of 10 Photos: A city tries to come together A man runs in front of Under Armour's Inner Harbor flagship store. The Baltimore-based sports apparel company is one of the city's few economic success stories, growing more than 28% in 2015.

Hide Caption 5 of 10 Photos: A city tries to come together Baltimore was once an important regional port. Its maritime industry suffered with the decline of American coal production, laying off thousands of port workers. The port has recently experienced renewed growth, now ranking 13th nationally in overall tonnage and employing nearly 15,000 workers.

Hide Caption 6 of 10 Photos: A city tries to come together A security guard looks out the window of a Tram rail car in downtown Baltimore. An ambitious rail project that would have connected the black community in West Baltimore to other areas of the city was recently killed by the governor.



Hide Caption 7 of 10 Photos: A city tries to come together Baltimore's U.S. Highway 40, known locally as the "Highway to Nowhere," cuts through West Baltimore. The expressway was never integrated into the interstate system. Its construction displaced hundreds of black families and strained relations between the black community and city government.

Hide Caption 8 of 10 Photos: A city tries to come together Voters cast their ballots at an early polling station in West Baltimore. Turnout in previous city elections was anemic, but early voting participation has been high this year. Hide Caption 9 of 10 Photos: A city tries to come together Photographer Devin Allen talks with a friend on camera for an upcoming HBO documentary on Baltimore. Allen was thrust into the national stage after his coverage of the riots on Instagram landed his work on the cover of TIME magazine.

Hide Caption 10 of 10

It also occurred two days after the city of Cleveland agreed to pay $6 million to the family of 12-year-old Tamir Rice, who died in 2014 after police shot him while he was in possession of a replica handgun.

While police spokesman Detective Donny Moses said Baltimore was quiet overnight and into Thursday, reaction was mixed on social media.

"We have more questions than answers today," Baltimore civil rights activist DeRay Mckesson said on Twitter . "Why did the Baltimore officers approach the 13-year-old child? Why did they shoot him?"

@BaltimorePolice Awesome job! I hope you arrest his mother for negligence or contributing to delinquency. She's unfit. — linda (@HotNostrilsrFun) April 27, 2016

One Twitter user told Baltimore police, "Awesome job! I hope you arrest his mother for negligence or contributing to delinquency. She's unfit."

But on Facebook, Darren Willis said in a reply to the police update on the incident that "cop kissing jerks" praising the department had missed the point.

"How was he to even know they were cops? He was 13 and ran away from grown-assed men who were strangers and armed. Details matter. I know, blame the target and the mom. It's easy for racists and idiots."