The gunfire took place at 1:24 pm (1924 GMT) at the Henry Pratt Company in Aurora, Illinois, a suburb 40 miles (65 kilometres) west of Chicago, the country's third-largest city.
Police named the suspect as Gary Martin, 45, of Aurora. He was a 15-year employee of the company and "information that we have indicates that he was being terminated today," said Aurora Police Chief Kristen Ziman.
The shooting came the day after Nancy Pelosi, the powerful speaker of the House of Representatives, said gun violence is a "national emergency" far more real than the one President Donald Trump ultimately declared Friday to build his wall at the Mexican border.
Police Chief Ziman did not have further details about why Martin was being fired, whether the killing was pre-meditated, or whether the victims were involved in his dismissal.
"Five employees were located deceased inside the building," and preliminary reports indicated they were killed before police arrived, Ziman told reporters.
One other employee was wounded but his life was not in danger, she said.
US gun control advocates see hopeful signs in 2018
Responding to multiple calls about a shooting at the company, which supplies water valves and employs about 200 people, officers were immediately confronted by Martin. He shot and wounded two of them with a Smith & Wesson handgun, the chief said.
As other officers arrived they entered the building, about half the size of a football field, to hunt for the retreating gunman and rescue people. Three more officers were shot but none of the five appeared to be in a critical condition, Ziman said.
After about 90 minutes, officers inside the "vast, vast building" located the gunman who opened fire again and was killed by returning fire from police, she said.
Witnesses told local media the shooter was a disgruntled employee. They said they locked themselves in nearby buildings as he began firing.
Aerial TV footage showed dozens of police cars, ambulances and fire trucks at the scene as officers with shields entered the complex.
John Probst, who was in the building when the shooting began but was able to escape, told the local ABC TV affiliate he recognized the gunman as a co-worker.
"What I saw was the guy running down the aisles with a pistol with a laser on it," he said. "We were just scared."
Gun control in the US: issues and proposals
Nancy Caal, an employee of a nearby repair workshop, told the Daily Herald newspaper she and three others had heard numerous emergency sirens, and so "went and shut the front gate and locked all of the doors."
In a tweet, President Trump praised the "great job by law enforcement in Aurora, Illinois" and sent "heartfelt condolences to all of the victims and their families. America is with you!"
The shooting came a day after the first anniversary of the Valentine's Day shooting at Marjory Stoneman Douglas High School in Parkland, Florida, where a former pupil killed 14 students and three staff, re-igniting a push for gun control.
In the year since, nearly 1,200 children still lost their lives to firearms and there have been other mass shootings including the October murder of 11 Jews at a Pittsburgh synagogue. In January a gunman killed five people at a bank in Sebring, Florida.
Illinois Governor JB Pritzker, a Democrat, said Friday's tragedy was part of an epidemic of gun violence.
"Tomorrow, the families of the victims will be less than whole. They join a group that should not exist, and yet continues to grow," Pritzker said.
A coalition of gun control advocacy groups also condemned the murderous attack, saying it was the 198th mass shooting in the last 10 years.
"This is a horrifying reminder of how hard we have to work to prevent gun violence," Holly Blastic, with Moms Demand Action for Gun Sense in America, said in a statement.
Definitions of "mass shooting" vary, but a Washington Post database has recorded 162 cases in which four or more people were killed since 1966. Many of the deadliest shootings have occurred in the last few years, the database shows.
In a presidential message Thursday to mark the Parkland anniversary, Trump recommitted to "ensuring the safety of all Americans."
"Let us declare together, as Americans, that we will not rest until our schools are secure and our communities are safe," Trump said.
COMMENTS
Comments are moderated and generally will be posted if they are on-topic and not abusive.
For more information, please see our Comments FAQ