Three police officers in the United States were killed and three others wounded in a shooting on Sunday.

The incident, in Baton Rouge, Louisiana, comes just two weeks after a black man was shot and killed by police in a confrontation that sparked nightly protests across the city, and reverberated across the US.

Police said the suspect was shot and killed at the scene. Authorities initially believed that two other assailants might be at large, but hours later said that no other active shooters were in the city.

The shooting - which took place just before 9am, less than a mile from police headquarters - came amid escalating tensions across the US between the black community and police. The races of the suspect and the officers were not immediately known.

It was the fourth high-profile deadly encounter in the United States involving police over the past two weeks.

The violence has left 12 people dead, including eight police officers, and sparked a national conversation over race and policing.

President Barack Obama said the killings were attacks "on the rule of law and on civilised society, and they have to stop".

He said there was no justification for violence against law enforcement and that the attacks are the work of cowards who speak for no one.

The attack began at a petrol station on Airline Highway. The shooter's body was next door, outside a fitness centre. Police said they were using a specialised robot to check for explosives near the body.

Louisiana governor John Bel Edwards rushed to the hospital where the shot officers were taken.

A police officer in tactical gear sets up in a parking lot while responding to a police shooting in Baton Rouge

"Rest assured, every resource available to the State of Louisiana will be used to ensure the perpetrators are swiftly brought to justice," Mr Edwards said in a statement.

A witness told television station WAFB that he saw a masked man in black shorts and shirt running from the scene where the three officers were killed.

Brady Vancel said the man looked like a pedestrian running with a rifle in his hand, rather than someone trained to move with a rifle.

Mr Vancel said he had gone to work on a flooring job near the petrol station when he heard semi-automatic gunfire and perhaps a handgun. He saw a man in a red shirt lying in an empty parking lot and "another gunman running away as more shots were being fired back and forth from several guns".

On Sunday afternoon, more than a dozen police cars with lights flashing were massed near a commercial area of car dealerships and chain restaurants on the highway. Police armed with long guns stopped at least two vehicles driving away from the scene and checked their trunks.

That area was about a quarter of a mile from a petrol station, where almost nightly protests had been taking place.

Five officers were rushed to Our Lady Of The Lake Regional Medical Centre, hospital spokeswoman Ashley Mendoza said.

Police guard the emergency room entrance of Our Lady Of The Lake Medical Center, where wounded officers were brought, in Baton Rouge, La.

Of the two who survived the shooting, one was in critical condition and the other was in fair condition. Multiple police vehicles were stationed at the hospital, and a police officer with a long gun was blocking the parking lot at the emergency room.

One officer was sent to Baton Rouge General Medical Centre and was being treated for non-life-threatening injuries, spokeswoman Meghan Parrish said.

Officers and deputies from the Baton Rouge Police Department and East Baton Rouge Sheriff's Office were involved, a spokeswoman said.

Police-community relations in Baton Rouge have been especially tense since the death of 37-year-old Alton Sterling, a black man killed by white officers on July 5 after a scuffle at a convenience store. The killing was captured on widely circulated mobile phone video.

It was followed a day later by the shooting death of another black man in Minnesota, whose girlfriend live streamed the aftermath of his death on Facebook. The next day, a black gunman in Dallas opened fire on police at a protest about the police shootings, killing five officers and heightening tensions even further.

Thousands of people have protested against Mr Sterling's death, and Baton Rouge police arrested more than 200 demonstrators.

An East Baton Rouge Police officer patrols Airline Hwy after 3 police officers were killed

Mr Sterling's nephew condemned the killing of the three officers.

Terrance Carter said the family just wants peace.

"My uncle wouldn't want this," Mr Carter said. "He wasn't this type of man."

Michelle Rogers said Sunday the pastor at her church had led prayers on Sunday for Mr Sterling's family and police officers, asking members of the congregation to stand up if they knew an officer.

Ms Rogers said an officer in the congregation hastily left the church near the end of the service, and a pastor announced that "something had happened".

"But he didn't say what. Then we started getting texts about officers down," she said.

Ms Rogers and her husband drove near the scene, but were blocked at an intersection closed down by police.

"I can't explain what brought us here," she said. "We just said a prayer in the car for the families."