A suspect is in police custody following an hours-long shooting standoff at a Planned Parenthood clinic in Colorado Springs, where at least one police officer and two civilians were killed Friday.

“The perpetrator is in custody,” Mayor John Suthers declared just after 5 p.m. Mountain time — more than five hours after an active shooter was first reported at the health-care clinic, spawning confusion that lasted through the afternoon over whether the gunman was at large or holed up at the medical facility with staff and patients.

The suspect was identified by the Colorado Springs Police Department as Robert L. Dear. Police were trying to determine his motive after his capture at the clinic. They said the suspect was armed with a long gun and also brought into the building several “items” that could have been explosive devices.

Besides the three deaths, at least four other police officers and five civilians were injured. ­Authorities said those individuals were all in good condition.

The University of Colorado at Colorado Springs said the officer killed was Garrett Swasey, 44, who had been with the campus police department for six years and responded to the initial reports of an active shooter.

A suspect is in police custody following a shooting at a Planned Parenthood clinic in Colorado, where one police officer and two civilians were killed Friday. (Reuters)

President Obama was briefed on the situation, a White House official said. Local police were joined at the scene by state investigators and federal agents from the Bureau of Alcohol, Tobacco, Firearms and Explosives and the FBI.

Health centers associated with Planned Parenthood have been the target of threats and violence because of the organization’s role in providing abortions and lobbying for reproductive rights. Abortion rights groups say threats against abortion providers rose sharply this summer in the wake of an undercover “sting” mounted by an antiabortion group that filmed one of its videos at a clinic in Denver.

At least four Planned Parenthood clinics have been targeted with arson since the videos were released. The increase in threats has led abortion rights groups to increase cooperation with local police and the FBI.

“Our hearts go out to the families and loved ones of the brave law enforcement officers who put themselves in harm’s way in Colorado Springs,” Cecile Richards, president and CEO of the Planned Parenthood Federation of America, said in a statement. “We are profoundly grateful for their heroism in helping to protect all women, men and young people as they access basic health care in this country.”

In a Twitter message late Friday, a clinic spokesperson said, “We are grateful to report that all our staff our safe and accounted for and are hoping for the best possible outcomes for the others wounded in the attack.”

Earlier, Vicki Cowart, president of Planned Parenthood of the Rocky Mountains, said in an interview on CNN that “we don’t yet know the full circumstances and motives behind this criminal action, and we don’t yet know if Planned Parenthood was in fact the target of this attack.”

In New York, Detective Brian Sessa said the police department had deployed response vehicles to Planned Parenthood locations throughout the city out of “an abundance of caution.” He added that there were no specific threats.

Timeline: What we know about the shooting in Colorado Springs

The incident in Colorado began on a traditionally quiet day of post-Thanksgiving relaxation about 11:30 a.m. Mountain time when police responded to a call for help from the Planned Parenthood clinic. The clinic sits in a bustling area near a shopping center, a medical building, a grocery store and restaurants.

A burst of gunfire early on gave way to relative calm in the afternoon, but witnesses said gunfire started again in the evening.

Police warned media not to set up too close to the scene because it was not secure. Many workers and shoppers in the area were told to hunker down in place, whether it be in the kitchen of their restaurant or the back seat of their car. Some remained there for hours as snow accumulated and the sky darkened.

As of 4 p.m., police had not identified or made voice contact with the shooter. Buckley said officers then managed to get into the building and shout at the suspect to give himself up, after which he emerged from the building with his hands raised.

Before that, police had evacuated a number of people from the building, and they were taken to a hospital for evaluation. Footage from television stations showed people in medical jackets and scrubs being ushered through the snow into waiting vehicles.

Sydney Downey, 20, who works at Sally Beauty Supply nearby, said people inside the store heard gunshots about 11:45 a.m.

“A lot of gunshots,” Downey said, “like, too many to even count.”

She said police and firefighters swarmed Centennial Boulevard, where the clinic is located, and crowded around a nearby bank.

An officer came by the beauty supply store to make sure that the doors were locked and that those inside were safe, she said.

“He said, ‘Get back away from the windows,’ and left, and that was it,” Downey said.

After that, Downey said, she remained huddled in a back room with the store manager and a customer.

Brigitte Wolfe, who works at a Japanese restaurant across the street from the clinic, said she first learned something was amiss when police SWAT and Bureau of Alcohol, Tobacco, Firearms and Explosives vehicles pulled up out front.

She heard no gunshots. “We just thought it was some random whatever happening, and then we turned on the news and started seeing what was going on,’’ she said.

Suddenly, about 3 p.m., police and ATF agents banged on the restaurant’s door “and told us to hide where there was no windows because the shooter was active,’’ Wolfe said.

She and several employees and customers hid in the restaurant’s kitchen.

Wolfe said the police and agents commandeered the restaurant’s dining room.

Gunshots were audible as police used an armored vehicle to evacuate people from the Planned Parenthood clinic.

Wolfe said that the medical facility had been the scene of protests most weekends but that there had never been any violence until Friday.

Alice Crites, Jennifer Jenkins, Julie Tate, Niraj Chokshi and Wesley Lowery contributed to this report.