FERGUSON, Mo. (AP) -- With measured remarks and a conciliatory tone, police, political leaders and civil-rights activists on Thursday sought to tamp down tensions after two police officers were shot in front of the Ferguson Police Department during a protest.

The officers were quickly released from the hospital, but St. Louis County Police Chief Jon Belmar said they could have easily been killed and called the attack "an ambush." Meanwhile, people were taken in for questioning after a SWAT team converged on a Ferguson home near the shooting site. Police did not immediately offer details.

The shootings marked the first time in eight months of tension in Ferguson that officers were shot at a protest, and the bloodshed threatened to inflame the already fraught relationship between police and protesters just as the city seeks reforms in the wake of a withering Justice Department report on racial bias in its law-enforcement practices.

The attack also seemed to create another layer of race-related mistrust after a week in which an unarmed young black man was killed by a white officer in Madison, Wisconsin, and a University of Oklahoma fraternity chapter was thrown off campus after a video surfaced showing members singing a racist chant.

In Washington, President Barack Obama took to Twitter to relay his prayers to the officers and to denounce violence against police. "Path to justice is one all of us must travel together," Obama wrote, signing the tweet with his initials to indicate the president personally composed it.

Attorney General Eric Holder said the gunman was "a damn punk" who was "trying to sow discord in an area that was trying to get its act together, trying to bring together a community that had been fractured for too long."

The shots were fired early Thursday just as a small crowd of protesters began to break up after a late-night demonstration that unfolded hours after the resignation of Ferguson Police Chief Tom Jackson.

The shots were believed to come from a handgun across the street from the police department, which has been a national focal point since the fatal Aug. 9 shooting of Michael Brown, who was black and unarmed, by a white police officer.

The gunman may have fired from up to 120 yards away, a long distance for most pistols. But with a line of roughly 20 officers standing in front of the building, the shooter did not have to be particularly accurate to hit two of them, Belmar said.

"We're lucky by God's grace we didn't lose two officers last night," he said.

A 41-year-old St. Louis County officer was shot in the right shoulder, the bullet exiting through his back. A 32-year-old officer from Webster Groves was wearing a riot helmet with the face shield up. He was shot in the right cheek, just below the eye, and the bullet lodged behind his ear.

More From KROC-AM