A gunman who shot at police officers in Colorado, killing one and wounding four others as they responded to a call, was a US army veteran who had served in Iraq.

Matthew Riehl, 37, is thought to have posted online rants railing at local law enforcement in the weeks before the deadly “ambush-style” attack.

Authorities are investigating what led the assailant to discharge “well over 100 rounds” at officers as they entered an apartment complex at Highland Ranch, 16 miles (28 kilometres) south of Denver. Two civilians were also injured.

Douglas County Sheriff Tony Spurlock said deputies wounded in a volley of gunfire had fought to save their slain colleague but were forced to give up and crawl to safety.

He said three deputies and a police officer tried to pull 29-year-old deputy Zackari Parrish, who had already been shot, out of the line of further gunfire but their own injuries hampered their efforts.

All five were investigating a 5.15am report of a disturbance at the apartment, which had been the subject of a noise complaint four hours earlier.

Mr Spurlock said authorities had departed earlier after hearing nothing and discerning no issue. When they returned they spoke with Riehl, who barricaded himself in a bedroom before suddenly opening fire with a rifle. He was killed in a shoot-out with a police tactical team.

A YouTube user identified as Riehl posted a video on 13 December calling for the firing of the Sheriff and railing against him in highly personal terms, it has emerged.

Two civilians were also reportedly injured in the gunfight, around 20 miles south of Denver (KMGH-TV)

​Riehl, who wears an Iraq combat veteran hat in the post, was deployed to serve in the Middle East for a year.

He enlisted in the Army Reserve in 2003 and spent time in Iraq in 2009 as part of a security mission with the 300th Field Artillery Regiment, according to a National Guard spokeswoman. Riehl was honourably discharged in 2012.

Mr Spurlock said officials were “familiar with him” from his having “had law enforcement contact on a number of occasions” but that Riehl did not have a criminal history.

He said the slain deputy, Mr Parrish, had joined the department roughly seven months ago and left behind a wife and two children.

“I can’t tell you how difficult it is for a leader to sit down with the spouse of an officer who was killed in the line of duty,” Mr Spurlock said. “They had many hopes and dreams and he was doing his job and doing his job well.”