SAN FRANCISCO – A bloodied gunman suspected of killing two women and seriously wounding a man at a shopping center in a crowded San Francisco neighborhood was arrested after opening fire on police officers, authorities said.

Officers encountered the suspect Friday outside the San Francisco Giftcenter & Jewelrymart in the trendy South of Market area. At first they were not sure if the man, who had blood on his clothes, was a shooting victim or a suspect, police Chief Greg Suhr said.

The man, whose name was not released, opened fire at officers while retreating into a restaurant, Suhr said. The man kept shooting until he apparently ran out of ammunition and surrendered, Suhr said.

Officers did not return fire because the sidewalks were crowded with shoppers and residents.

The suspect was treated at a hospital for non-life-threatening injuries. A gun and a knife were recovered from the scene.

SWAT officers swept the building, but police said there were no outstanding suspects.

"We believe from video in an adjacent store that there was one suspect. We believe that it is the suspect we have in custody," Suhr said.

The man arrested had been in that area before, according to witnesses.

Inside the shopping center, police found the two women dead in the lobby. One woman was shot and the other suffered "wounds from an edged weapon," police said. Their names were not immediately available. A witness said at least one of the women worked at a jewelry store inside the building.

Another man with life-threatening gunshot and stab wounds was taken to a hospital, police said.

The shopping center is just blocks from the Hall of Justice, which is the home of San Francisco Superior Court, a jail and police headquarters. Several tech companies, including online game maker Zynga, are also in the neighborhood.

Investigators were trying to determine if Friday's shooting was connected to a botched robbery.

Officers were interviewing witnesses who ducked for cover when the shooting began.

"Somebody was crying or yelling for help. Then I saw the SWAT. There was a dozen of them. They told us to lock ourselves in," Veronica Sirois, who was shopping at the gift center, told the San Francisco Chronicle. "I saw blood on the way out and a pair of bodies."