COLORADO SPRINGS — A gun battle erupted inside a Planned Parenthood center here on Friday when a man armed with an assault-style rifle opened fire and began shooting at officers as they rushed to the scene. The authorities reported that three people were killed, a police officer and two civilians, and nine were wounded before the suspect finally surrendered more than five hours after the first shots were fired.

A police official in Colorado Springs identified the man in custody as Robert Lewis Dear.

The police did not describe the motives of the 57-year-old gunman. For hours on Friday, officers traded gunfire with him inside the clinic before they were able to shout to the man and persuade him to give up, according to Lt. Catherine Buckley, a police spokeswoman.

“The perpetrator is in custody,” Mayor John Suthers said at an evening news conference. “There is a huge crime scene that has to be processed,” he said, “and we have to determine how many victims there are.”

Lieutenant Buckley said the gunman had brought several suspicious items to the clinic, and investigators were trying to determine whether they were explosives.