UPDATE: Five people were killed on Thursday when a man with a shotgun opened fire in the Capital Gazette newsroom in Annapolis, Maryland’s capital, in a "targeted attack," police said. The suspect had sued the paper six years ago and lost.

"This person was prepared to shoot people. His intent was to cause harm," Bill Krampf, deputy police chief of Anne Arundel County, said at a news conference Thursday evening. Two people suffered superficial wounds, possibly from broken glass, he said.

Three senior law enforcement officials briefed on the matter told NBC News that the suspect has been identified as Jarrod Ramos, 38, of Maryland.

Ramos sued the Capital Gazette for defamation in 2012 after a columnist wrote about his guilty plea to criminal harassment in 2011. His case was dismissed, and an appeals court affirmed the decision.

On Thursday around 2:40 p.m., police were notified about an active shooter, authorities said. The gunman also had smoke grenades that he used when he entered the building, Krampf said. Earlier, Krampf had identified the grenades as a "possible explosive device."

Asked about reports that Ramos had issues with the newspaper a few years ago, Krampf said, "That's what I'm hearing," but added that investigators had yet to confirm that.

"He entered the building with a shotgun and he looked for his victims" inside, Krampf said.

Phil Davis, a Gazette crime reporter who was in the office, recounted the shooting on Twitter.

"Gunman shot through the glass door to the office and opened fire on multiple employees," Davis said. "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 said in another tweet.

Anthony Messenger, who is believed to be an intern at the Gazette, said on Twitter: “Active shooter 888 Bestgate please help us.” The newspaper's office is at 888 Bestgate Road.

Senior law enforcement sources briefed on the investigation told NBC News that Ramos had been identified through the use of facial recognition software. The sources said earlier that he had somehow obscured his fingerprints, making identification difficult.

In a later interview with The Baltimore Sun, which owns the Capital Gazette, Davis said it "was like a war zone" inside the newspaper’s offices.

Davis said he and others were hiding under their desks when the gunman stopped firing.

"I don't know why. I don’t know why he stopped,” Davis said.

Anne Arundel County Police Lt. Ryan Frashure said there was no exchange of gunfire between the gunman and police.

The Baltimore Sun said police had also been sent to its headquarters as a precaution. The Capital Gazette is one of the oldest publishers in the country, starting in 1727 with the Maryland Gazette.

Aerial video showed people leaving the building with their hands up and a heavy police presence.

Krampf said threats were sent to the newspaper on social media, but police are trying to confirm what account the threats were sent from, and who actually sent them. “To my knowledge, those threats were as early as today,” he said.

“They were general threats towards the Capital” Gazette, he said. “They indicated violence."

The victims were shot on the first floor of the building, Krampf said. He said he could not confirm whether all of those killed were employees at the newspaper.

“We have no knowledge at all that he was targeting anyone specific,” Krampf said.

President Donald Trump has been briefed about the shooting, the White House said. "My thoughts and prayers are with the victims and their families. Thank you to all of the First Responders who are currently on the scene," the president said on Twitter.

Maryland Gov. Larry Hogan said on Twitter that he was "absolutely devastated to learn of this tragedy in Annapolis."

"It's a tragic situation, but there was some very brave people that came in and kept it from being worse," Hogan said at a news conference, referring to the police response.

Police departments in New York City and Chicago said they were monitoring developments and would be checking in or deploying resources to media outlets.

The New York Police Department said it had deployed counterterrorism teams to media organizations around the city as a precaution.

"These deployments are not based on specific threat information, but rather out of an abundance of caution until we learn more about the suspect and motives behind the Maryland shooting," the NYPD said.

Tronc Inc., the company that owns The Baltimore Sun, said in a statement, “We are deeply saddened today by the attack in our Capital-Gazette newsroom.”

“Our thoughts and prayers are with the victims and their families,” Chairman and CEO Justin Dearborn said. “We are focused now on providing our employees and their families with support during this tragic time. We commend the police and first responders for their quick response.”

Noah Turner, an Annapolis resident, said he was nearby when the shooting occurred and saw two police SWAT vehicles and around 10 police cars heading to the scene. "It's crazy," Turner said.

"I've never seen so many police cars in my life," he said. "You would not ever think it would happen here."

Chase Cook, a reporter at the Capital Gazette, said on Twitter, "I can tell you this: We are putting out a damn paper tomorrow."