Two civilians also were shot and the suspect was shot and killed later by police, Sheriff Tony Spurlock said.
The sheriff said Deputy Zackari Parrish, 29, was killed. The four injured officers are in stable condition, Spurlock told reporters.
"This is a tragic day that we will be feeling for a long time," Spurlock said. "Zack was a good kid, smiley kid. He was eager to work, eager to serve."
The suspect, who authorities identified as 37-year-old Matthew Riehl, had barricaded himself in a bedroom before he suddenly opened fire with a rifle, hitting four deputies in the apartment, authorities said.
"There were well over 100 rounds fired ... from the suspect," Spurlock said.
The wounded deputies crawled to safety as other law enforcement agencies responded to the shots fired call.
A Castle Rock SWAT officer was wounded in a shootout 90 minutes after the deputies were fired upon, according to a news release
from the sheriff's office.
The two wounded civilians were not in the apartment.
The deputies were wearing ballistic vests but were shot in areas the vests didn't cover, Spurlock said.
Spurlock said the suspect has had previous contact with law enforcement "throughout the metro area," but has no criminal history.
Two calls to the suspect's apartment
The incident began about 5:17 a.m. when the first deputy arrived at the Copper Canyon Apartments in Highlands Ranch, about 20 miles south of Denver.
It was the second time deputies had gone to the apartment Sunday. There was a noise complaint call about 3 a.m., but when deputies got there, there was no noise. After they spoke with the roommate in the apartment, they left, the sheriff's office said.
"One male said the suspect was acting bizarre and might be having a mental breakdown," the news release said.
The second call was dispatched as a domestic disturbance, and by 5:35 a.m. the four deputies had arrived at the scene.
The sheriff's office said the roommate returned to the apartment, gave deputies a key and said they could enter the residence. The roommate left, police said.
Not long after the deputies found the suspect barricaded in his room, Riehl opened fire, Spurlock said.
"They all went down within almost seconds of each other so it was more of an ambush type of attack on our officers," Spurlock said.
The sheriff said he was told by a doctor at the emergency room that Parrish suffered mortal wounds.
The suspect was killed about 90 minutes later during a shootout when a tactical team went into the apartment, the sheriff's office said.
Escorted to the coroner
A motorcade accompanied the fallen officer from a hospital in nearby Littleton to the coroner's office.
Three patients with non-critical injuries were treated and released from Sky Ridge Medical Center in Lone Tree, Colorado, hospital spokeswoman Linda Watson said.
Steven Silknitter, a resident of the Copper Canyon apartment complex, said he rushed home to check on his fiancée after hearing of the shooting and arrived to hear a "barrage of gunfire exchanged."
The area was blocked off, and Silknitter said he saw at least 20 police vehicles.
"I was deathly afraid that I was going to go home and she'd be gone. ... I didn't know what I was going to find," he told CNN affiliate KMGH
"It's the last thing I would have thought of at my complex," he said. "It's like something out of a movie."
President Trump tweeted his "deepest condolences to the victims of the terrible shooting in Douglas County ... and their families."
The four injured officers are Mike Doyle, 28; Taylor Davis, 30; Jeffrey Pelle, 32, of the Douglas County Sheriff's Department, and Tom O'Donnell, 41, an officer with the Castle Rock Police Department.
Pelle is the son of Boulder County Sheriff Joe Pelle.
Parrish is survived by his wife and two young children. He joined the sheriff's department about seven months ago, after two years with the Castle Rock Police Department.
Correction: A previous version of this article gave the incorrect age for Officer Tom O'Donnell. He is 41.