Cops on Wednesday said a vigilant passerby alerted them to the robbery turned hostage situation inside a Chinese takeout overnight.

The owner of the takeout was smoking a cigarette outside a side entrance to the store, on the corner of 42nd and Ogden streets in West Philly, as he closed up shop for the night around midnight when he was approached by a man in his 20s who forced him back inside the store, Lt. John Walker of the Southwest Detective Division said.

Two other alleged robbers went into the store, cops said. At least one of the three assailants was armed with a handgun.

A passerby saw the storeowner being forced inside and attempted to dial 911, Walker said, but his cell phone battery died. He then found and flagged down a police officer.

When cops arrived at the scene, they looked through the partially closed metal security grates and saw two men in the front of the store stuffing money into their pockets, Walker said. Police said cops at the scene could also hear people inside crying.

Cops declared a barricade and called SWAT officers to the scene. The standoff lasted about two and a half hours while the trio of robbers attempted to find ways to escape the building through the roof to elude capture, Walker said, before they surrendered to cops around 2:30 a.m.

The storeowner was pistol-whipped during the attempted robbery and suffered a bump and some cuts to his head, but was not wounded badly enough to need medical treatment. A woman and an 11-year-old girl who were also inside the building at the time were not physically harmed.

All three of the robbers, who are all in their 20s, were arrested at the scene.

Walker said cops were still gathering evidence Wednesday and recovered one 9mm handgun inside the store around 10 a.m. The three alleged robbers were still being processed Wednesday night and hadn't yet been officially charged.