COLORADO SPRINGS, Colo. — A gunman who opened fire in a Planned Parenthood clinic was arrested Friday after engaging in gun battles with authorities during an hours-long standoff that killed three people and wounded nine others, officials said.

A police officer with the University of Colorado in Colorado Springs was among those killed in the rampage, police said. Two civilians also died, and nine other people, including five police officers, were wounded.

A law enforcement official identified the gunman, who was in custody, as Robert Lewis Dear of North Carolina. The official, who had direct knowledge of the case, spoke on condition of anonymity because the official was not authorized to speak to the media about the ongoing investigation. No other details about Dear were immediately available.

Authorities said they do not know the motive for the attack or whether the shooter had any connection to Planned Parenthood.

“We don’t have any information on this individual’s mentality, or his ideas or ideology,” said police Lt. Catherine Buckley.

Planned Parenthood said in a prepared statement that it did not know the full circumstances or motives behind the attack at the Colorado Springs clinic, or whether the organization was the target.

For several hours, the firing of a long gun was the only indication police had that the shooter was in the building, Buckley said. Officers finally made voice contact by shouting to him and persuaded him to surrender about five hours after the shooting began, she said.

Video from The Denver Post showed a tall man in a white T-shirt being led away by police as snow fell on the frigid evening.

With the immediate threat over, authorities turned their attention to inspecting unspecified items the gunman left outside the building and carried inside in bags.

The University of Colorado in Colorado Springs police department identified the officer killed as Garrett Swasey, 44, a six-year veteran of the force. No other details were available about the civilians killed in the attack, and police said the nine wounded victims were in good condition.

The gunfire at the clinic sent people inside racing for cover. Jennifer Motolinia hid behind a table in the clinic and called her brother, who said he heard multiple gunshots in the background.

“She was telling me to take care of her babies because she could get killed,” Joan Motolinia said of his sister, the mother of three.

He rushed to the clinic but was frustrated because a police barricade kept him from getting close.

“People were shooting for sure. I heard someone shooting. There was a lot of gunfire. She was calm, she was trying to hide from those people,” he said.

Police in the building ushered the staff and patients to the second floor without saying why, employee Cynthia Garcia told her mother-in-law, Tina Garcia.

Then Cynthia Garcia heard gunshots, but she couldn’t tell where they were coming from, Tina Garcia told The Associated Press.

Police cordoned off the clinic, nearby medical offices and a shopping center. Authorities ordered everyone in the area to take shelter where they were.

Denise Speller, manager of a nearby hair salon, said she heard as many as 20 gunshots in less than five minutes.

She told The Gazette newspaper that she saw two officers near a bank branch, not far from the Planned Parenthood facility.

One of the officers appeared to fall to the ground, and the other officer knelt down to help and then tried to get the officer to safety behind a patrol car, she said. Another officer told Speller to seek shelter inside the building.

“We’re still pretty freaked out,” Speller said by phone while still trapped inside the salon. “We can’t stop shaking.”

Shelley Satulla said she saw five or six people put on stretchers and placed in ambulances lined up next to the King Soopers shopping center near the clinic.

Mike Pelosi, who works at a deli at a nearby King Soopers grocery store, said he heard over the store’s loudspeaker just before noon that nobody could leave the store.