A gunman blasted his way into the Capital Gazette newsroom in Annapolis with a shotgun Thursday afternoon, killing five people, authorities said.

Journalists dived under their desks and pleaded for help on social media. One reporter described the scene as a “war zone.” A photographer said he jumped over a dead colleague and fled for his life.

The victims were identified as Rob Hiaasen, 59, a former feature writer for The Baltimore Sun who joined the Capital Gazette in 2010 as an assistant editor and columnist; Wendi Winters, 65, a community correspondent who headed special publications; Gerald Fischman, 61, the editorial page editor; John McNamara, 56, a staff writer who had covered high school, college and professional sports for decades; and Rebecca Smith, 34, a sales assistant hired in November.

Two others were injured in the attack that began about 2:40 p.m. at the Capital Gazette offices at 888 Bestgate Road in Annapolis.

Police took a suspect into custody soon after the shootings. He was identified as Jarrod W. Ramos, a 38-year-old Laurel man with a long-standing grudge against the paper.

Ramos was charged with five counts of first-degree murder, according to online court records. He did not have an attorney listed; a bail review hearing is scheduled for 10:30 a.m. Friday in Annapolis.

“This was a targeted attack on the Capital Gazette,” said Anne Arundel County Deputy Police Chief William Krampf. “This person was prepared today to come in. He was prepared to shoot people.”

Local, state and federal law enforcement officials cordoned off the Laurel apartment complex listed as the address for Ramos Thursday evening.

A gunman blasted his way into the Capital Gazette newsroom in Annapolis with a shotgun June 28, killing five people and injuring two others, authorities said.

Ramos’ dispute with the Capital Gazette began in July 2011 when a columnist wrote about a criminal harassment case against him. He brought a defamation suit against the columnist and the organization’s editor and publisher. A court ruled in the Capital Gazette’s favor, and an appeals court upheld the ruling.

Neither the columnist, Eric Hartley, nor the editor and publisher, Thomas Marquardt, are still employed by the Capital Gazette. They were not present during the shootings.

Police said the suspect used “smoke grenades” in the attack. They said 170 people were inside at the time.

The Capital Gazette is owned by The Baltimore Sun.

Phil Davis, a Capital crime reporter who was in the building at the time of the shooting, said multiple people were shot as he and others hid under their desks. He said there was a single male gunman.

“Gunman shot through the glass door to the office and opened fire on multiple employees,” he wrote on Twitter. “Can’t say much more and don’t want to declare anyone dead, but it’s bad.”

“There is nothing more terrifying than hearing multiple people get shot while you’re under your desk and then hear the gunman reload.”

Davis later told The Sun it “was like a war zone” — a scene that would be “hard to describe for a while.”

“I’m a police reporter. I write about this stuff — not necessarily to this extent, but shootings and death — all the time,” he said. “But as much as I’m going to try to articulate how traumatizing it is to be hiding under your desk, you don’t know until you’re there and you feel helpless.”

Davis said he and others were hiding under their desks when the shooter stopped firing. Then police arrived and surrounded the shooter.

Photographer Paul Gillespie had finished editing photos from one assignment and was preparing for the next when he heard shots behind him and the newsroom’s glass doors shatter.

He heard another shot, he said, dived under a co-worker’s desk “and curled up as small as I could.”

“I dove under that desk as fast as I could, and by the grace of God, he didn’t look over there,” he said. “I was curled up, trying not to breathe, trying not to make a sound, and he shot people all around me.”

Gillespie said he heard one colleague scream “No!,” then a shot. Then another colleague’s voice, and another shot. He could hear the gunman approaching his hiding place.

“I kept thinking, ‘I can’t believe I’m going to die. I can’t believe this.’ ” Gillespie said.

But the gunman passed him, he said, and continued to shoot. Eventually, there was a lull in the shots. Gillespie stood and ran for the exit, through the shattered glass, jumping over the body of a colleague he believed was dead as another shot rang out in his direction.

He ran to a nearby bank and screamed for people to call the cops.

“I feel like I should be helping to cover it,” he said, “but I’m a mess.”

Authorities said police responded to the scene within a minute of the shooting.

“If they were not there as quickly as they were, it could have been a lot worse," Annapolis Mayor Gavin Buckley said.

Officials at the Maryland Shock Trauma Center in Baltimore confirmed that the hospital was treating at least one victim. County Executive Steve Schuh said others were being treated at Anne Arundel Medical Center.

Loren Farquhar, a medical center spokeswoman, said the hospital received two patients, both with minor injuries not from gunfire.

The injured employees were identified as Rachael Pacella, a reporter who covers education and the Naval Academy, and Janel Cooley, a sales representative who covers downtown Annapolis. Both were treated and released.

A spokeswoman for the Baltimore Sun Media Group said the company was “deeply saddened” by the shooting.

“Our thoughts and prayers are with our colleagues and their families,” spokeswoman Renee Mutchnik said. “Our immediate focus is on providing support and resources for all our employees and cooperating with the authorities as this situation is still under investigation.”

President Donald Trump wrote on Twitter that he had been briefed on the shooting.

“My thoughts and prayers are with the victims and their families,” he wrote. “Thank you to all of the First Responders who are currently on the scene.”