CHAPEL HILL, N.C. (AP) _ A gunman opened fire on a the town's main street Thursday, killing two people near the University of North Carolina and peppering cars and the post office with fire from his high-powered rifle.

The man began shooting randomly as he walked down the street around 2 p.m., striking a police officer and a student who escaped unharmed when the bullet ricocheted off his keys.

The gunman was shot in the legs by police, then tackled by a bystander who was shot in the struggle. All three of the wounded were taken to the hospital; none suffered life-threatening injuries, authorities said.

One person was gunned down in front of a sorority house, and a bicyclist was killed a half-block away on the steps of the rooming house where he lived. Neither of the dead was students, police said.

``He was shooting at me, he was shooting at random, and he was shooting at anybody he saw,'' said Bob Epting, 50, an attorney in Chapel Hill. ``He looked like he was on his way to his own death.''

The gunfire began near the post office building across the street from the University of North Carolina at Chapel Hill.

Orange County District Attorney Carl Fox said the man fired 10 to 15 rounds from a semiautomatic M-1, including several into the back of the post office building, which also contains his offices and a courtroom.

``This came up like a sudden storm,'' grocery store owner Ed Donegan said. ``There was a tremendous amount of shooting.''

Jason Howard, a doctoral candidate in microbiology, encountered the gunman was he was walking down the street. The gunman was carrying what appeared to be a high-caliber rifle and a camouflage jacket, he said.

``He looked right at me,'' Howard said. ``I was scared.''

Howard said the gunman fired at him, but the bullet went through his pants and ricocheted off his keys. He was not hurt.

The gunman shot and killed a bicyclist as he was trying to flee, said witness Matt Mesmer. The bicyclist's body was sprawled on the steps of a rooming house, about a half-block from the post office.

The other victim fell in front of a sorority house. A backpack stuck out from under a sheet police used to cover the body.

Two police cars were hit by bullets three or four times each, and a female officer in one car was shot in the left hand. Two civilian cars also were hit.

After the killings, the gunman hid in a doorway, then came out and started firing at police, said Chris Pierson, a university senior and a bartender at the nearby Tammany Hall bar. He fell after being hit in the legs by police, but continued firing, Pierson said.

The bar's manager, William Leone, snuck up on the gunman. When he stopped shooting to change the clip in his gun, Leone tackled him, Pierson said.

In the process, Leone, a former Marine, was shot in the shoulder, said Brian Rathjen, owner of the Anchor Bar. ``He's the hero,'' Rathjen said.