A plant manager who was among five people gunned down in the Illinois workplace massacre texted his wife, “I love you, I’ve been shot at work” just moments before dying.

Terra Pinkard revealed her husband Josh’s final message to her Friday afternoon — when gunman Gary Martin opened fire at the Henry Pratt Co. warehouse in Aurora upon learning in a meeting that he was being let go.

In an emotional Facebook post on Sunday, Pinkard called the tragic shooting a “literal nightmare.” Her husband, 37, of Oswego, was in that meeting with Martin.

“I received a text at 1:24 from my precious husband that said I love you, I’ve been shot at work. It took me several times reading it for it to hit me that it was for real,” she wrote. “I called his phone several times, text, FaceTime, nothing. I called his plant and a lady answered and said she was barricaded in her room and police were everywhere. Of course my heart dropped.”

Pinkard went on to say how she had to wait for hours to learn that Josh was among the dead.

“The police told us there were fatalities. He read my husband’s name,” she wrote. “I immediately left and went to get my kids. With my pastors help, since family was still on planes to get to us, I told my children their dad did not make it and is in heaven with Jesus. I’ve never had to do something that hard.”

The post went on to pay tribute to Josh, whom she called “the smartest person I’ve ever met” and “my best friend.”

“I want to shout from the rooftops about how amazing Josh was! … The man who was dying and found the clarity of mind for just a second to send me one last text to let me know he would always love me,” Pinkard wrote. “This unbelievable person was robbed from us.”

The other victims were identified as Clayton Parks, 32; Russell Beyer, 47; Vicente Juarez, 54; and Trevor Wehner, 21, a college student who was on the first day of his internship.

Josh and three other colleagues were in the meeting with Martin when they were shot. Martin gunned down a fifth employee before injuring another and five police officers.

It was unclear why Martin, a 15-year employee, was fired from the plant, which manufactures various types of valves.