BEIJING — A jobless man bent on revenge and armed with a butcher knife stormed a police station in Shanghai on Tuesday, slashing and stabbing officers inside and killing at least five, authorities and local media said.

The Shanghai Public Security Bureau said in a news release that a 28-year-old man with the surname Yang set a fire outside the building's gate and then rushed inside and began attacking officers.

Five officers died after being taken to a hospital, while four other police officers and a security guard were hurt, the statement said.

Some suffered stab wounds to the chest while others were slashed across the face or neck, the Chinese news Web portal reported.

News photos showed the large bloodstained butcher knife allegedly used in the attack and Yang sitting handcuffed on a chair after he was detained. One sleeve of his white T-shirt appeared to be blood spattered.

Yang, who is from Beijing and unemployed, said he was seeking revenge after officers at the station in Shanghai's Zhabei district investigated him last year for allegedly stealing bicycles, police said. He was taken into custody at the station.

It was not immediately clear how the attacker, who appeared slight in the news photo, managed to stab so many police officers and why he was not detained after setting a fire outside the building. Though Chinese police are permitted to carry guns, the attack took place in an office building and it was possible officers there were not armed.

A woman at the Zhabei district station referred questions to the Shanghai Public Security Bureau. Phones rang unanswered in the bureau's propaganda department.

Violent street crime is rare in China, where private gun ownership is virtually banned.