A man who shot three people before storming into the Kansas factory where he worked and shooting 15 others, killing three of them, had just been served a protection from abuse order that probably triggered the attack, a sheriff said.
All of the dead were shot inside Excel Industries, a plant in Hesston that makes lawnmower products, Harvey County sheriff T Walton said. Of those hurt, 10 were critically wounded, he said.
Mr Walton would not identify the suspect.
The shooting came less than a week after authorities say a man opened fire at several locations in the Kalamazoo, Michigan, area, leaving six people dead and two severely wounded.
Mr Walton said his office served the suspect with the protection order at around 3.30pm on Thursday, which was about 90 minutes before the first shooting happened. He said such orders are usually filed because there is some type of violence in a relationship, but he did not disclose the nature of the relationship in question.
While driving to the factory, the gunman shot a man on the street in the nearby town of Newton, striking him in the shoulder. A short time later, he shot someone else in the leg at an intersection.
"The shooter proceeded north to Excel Industries in Hesston, where one person was shot in the car park before he opened fire inside the building," the department said in a release. "He was seen entering the building with an assault-style long gun."
Martin Espinoza, who works at Excel, was in the plant during the attack. He heard people shouting to others to get out of the building, then heard popping, then saw the shooter, a co-worker he described as typically pretty calm.
Mr Espinoza said the shooter pointed a gun at him and pulled the trigger, but the weapon was empty. At that point, the gunman got a different gun and Mr Espinoza ran.
"I took off running. He came outside after a few people, shot outside a few times, shot at the officers coming on to the scene at the moment and then reloaded in front of the company," Mr Espinoza said. "After he reloaded, he went inside the lobby in front of the building and that is the last I seen him."
A Hesston officer responding to the scene exchanged fire with the shooter, who was killed. The officer was not injured.
Mr Walton said that about 150 people were probably in the plant at the time of the shooting and that the law enforcement officer who killed the suspect "saved multiple, multiple lives". He said the gunman also had a pistol.
The officer who killed the man is "a hero as far as I'm concerned", Mr Walton said.
Erin McDaniel, spokeswoman for the nearby city of Newton, said the suspect was known to local authorities. She would not elaborate.
A nearby college was briefly locked down.
Later on Thursday night, several law enforcement vehicles surrounded the suspect's home in a Newton trailer park. The Harvey County Sheriff's Department initially said authorities believed the suspect's roommate could be inside. But Ms McDaniel said later that the standoff had ended and no one was inside.
Hesston is a community of about 3,700 residents about 35 miles north of Wichita.
Excel Industries was founded there in 1960. The company manufactures Hustler and Big Dog mowing equipment and was awarded the Governor's Exporter of the Year award in 2013 from the Kansas Department of Commerce.
Governor Sam Brownback issued a statement calling the shootings "a tragedy that affects every member of the community".
Mr Walton said the FBI and the Kansas Bureau of Investigation had been called in to assist.
"This is just a horrible incident. There's going to be a lot of sad people before this is all over," Mr Walton said.