Police early Thursday shot and killed a heavily armed man who invaded a bar near the University of California campus, killing one student and holding others hostage for seven hours.

Police shot the gunman as he walked out of the bar shortly after 7 a.m. Paramedics rushed the wounded man away as hostages streamed out into the street and police tried to round them up to collect their statements. Twenty three hostages were taken to police headquarters."He just came out. We just shot him," police Capt. Philip Doran said. "We're getting hostages out now."

The wounded gunman, identified as Mehrdad Dashti, was taken to Highland General Hosptial in Oakland, where he was pronounced dead on arrival.

Doran said Dashti was angry over his failure to obtain a government loan to attend the University of California.

"(The) motive as far as I understand - he was very angry. He had been turned down for a student loan. He was angry at the federal government for other reasons besides that. So, whatever his motive may have been, at least those two were part of it," Doran said.

The gunman held as many as 20 people hostage as he kept police at bay in a standoff that lasted for nearly seven hours, authorities said.

At least seven people were wounded during the rampage.

The gunman began shooting sporadically at patrons inside Henry's bar in the Durant Hotel, a block south of the UC Berkeley campus, shortly after midnight, Doran said.

He spent the next seven hours firing his gun and killing time by sexually harassing his white female hostages, witnesses said.

Two women released from the bar said Dashti appeared irrational and ordered non-white appearing women to "run out and tell the police . . . that they had done this to me. This isn't my fault I wrote several letters to your FBI."

Several blonde women, they said, were ordered to "take off their pants."

"After the girls took off their pants, at least the blondes, he had them do something sexually perverse," a former hostages said.