A man found shot in the head inside a car at Seventh and Callowhill Streets on Monday night may have been shot while trying to rob someone a few minutes earlier with what turned out to be a BB gun, Philadelphia police said Tuesday.

The suspected robber remained hospitalized in critical condition, while a 17-year-old who may have assisted him in the robbery was taken into custody. No charges have yet been filed and police didn’t identify them. But police did say the 21-year-old man they may have targeted was legally carrying a firearm.

According to police, the events began around 5:50 p.m., when a 29-year-old man got out of his gray Chevrolet Cruze on the 300 block of South 10th Street. Police said someone put a gun to the back of his head and said: “Give me everything.” The man handed over his cellphone and wallet, while the person with the gun and another male — both described as wearing dark clothing — got into the car and drove away.

The 29-year-old ran to his apartment and called police. He told officers that his stolen iPhone “was tracking to the area of Seventh and South Street,” police said, but officers didn’t find the suspects there.

A few hours later, at 8:51 p.m., police said, a 21-year-old man was walking at 18th and Vine Streets when a gray Chevrolet Cruze stopped in front of him. Two males got out of the car, police said, and one pointed a gun at him. The other male began frisking the 21-year-old, police said, demanding money and his cellphone.

That’s when the 21-year-old allegedly pulled out a 9mm handgun he had a valid permit to carry.

“Fearing for his life, and fearing that his firearm would be taken, he pulled out that gun and fired two shots,” police said. The man fired a third round as he was shoved to the ground, then ran away and flagged down a security guard, who called police.

Officers then found the 17-year-old at 18th and Vine, who told them his brother had been shot during a robbery. But the security guard then approached the police and told officers he had been talking to the actual victim in the robbery.

That man then identified the 17-year-old as one of the perpetrators, police said. Officers at the scene found several fired cartridge casings from a 9mm, along with the firearm used in the robbery attempt, which police said was a BB gun.

About 10 minutes after the shooting, officers found a gray Chevrolet Cruze at Seventh and Callowhill with a man slumped over in the driver’s seat with a gunshot wound to the head. He was taken to Temple University Hospital in critical condition.

Police said they found a wallet on him that belonged to the 21-year-old robbed at 18th and Vine.

It was not clear how the man might have driven the car from the robbery scene after being shot in the head, or why he might have driven off without his alleged coconspirator.