A man armed with smoke grenades and a shotgun attacked journalists at a newspaper in Maryland's capital, killing five people before police quickly stormed the building and arrested him, police and witnesses said.

Police said the suspect was a white man in his late 30s whose shotgun rampage at The Capital Gazette followed social media threats directed at the newspaper.

A law enforcement official said the suspect has been identified as Jarrod W Ramos.

Authorities said a gunman entered the building in a targeted attack and "looked for his victims".

He had smoke grenades and fired a shotgun at his victims, according to Anne Arundel County acting police chief William Krampf.

"This person was prepared today to come in, this person was prepared to shoot people. His intent was to cause harm," Mr Krampf said.

Among the victims was veteran journalist and columnist Rob Hiaasen, 59, brother of novelist Carl Hiaasen.

Carl Hiaasen said he was "devastated and heartsick" at the loss of his brother, "one of the most gentle and funny people I've ever known."

Three other journalists and a staffer were killed: editorial page editor Gerald Fischman; special publications editor Wendi Winters; writer John McNamara, and sales assistant Rebecca Smith.

Mr Krampf said the gunman was a Maryland resident and search warrants were being sought for his home.

Phil Davis, a reporter who covers courts and crime for the paper, tweeted that the gunman shot out the glass door to the office and fired into the newsroom, sending people scrambling for cover under desks.

"A single shooter shot multiple people at my office, some of whom are dead," he wrote.

Mr Davis added: "There is nothing more terrifying than hearing multiple people get shot while you're under your desk and then hear the gunman reload."

The attacker had mutilated his fingers in an apparent attempt to make it harder to identify him, according to a law enforcement official. Another official said investigators identified the man using facial recognition technology.

The shooting - which came amid months of verbal and online attacks on the "fake news media" - prompted New York City police to immediately tighten security at news organisations in the nation's media capital.

At the White House, spokeswoman Lindsay Walters said: "There is no room for violence, and we stick by that. Violence is never tolerated in any form, no matter whom it is against".

Authorities said the suspect was undergoing questioning by detectives.

In 2012, Ramos filed a defamation lawsuit against the paper, alleging he was harmed by an article about his conviction in a criminal harassment case a year earlier.

The suit was dismissed by a judge who wrote Ramos had not shown "anything that was published about you is, in fact, false." An appeals court later upheld the dismissal.

Mr Krampf confirmed five deaths and said two people had superficial wounds. Authorities had said earlier that several people were gravely wounded.

Police spokesman Lieutennt Ryan Frashure said officers raced to the scene, arriving in 60 seconds, and took the suspect into custody without an exchange of gunfire.

About 170 people in all were evacuated from the building as a multitude of police cars and other emergency vehicles converged on the scene. People could be seen leaving the building with their hands up.

The newspaper is part of Capital Gazette Communications, which also publishes the Maryland Gazette and CapitalGazette.com.

In an interview with The Capital Gazette's online site, Mr Davis said it "was like a war zone" inside the newspaper's offices - a situation 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 traumatising it is to be hiding under your desk, you don't know until you're there and you feel helpless."

Mr Davis told the paper he and others were still hiding under their desks when the gunman stopped firing.

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

Reporter Selene San Felice told the CNN broadcast outlet she was at her desk when she heard the shooting and ran with some others to a back door only to find it locked. She said she saw a colleague steps away as he was shot but did not get a view of the shooter as she sought to hide.

"I heard footsteps a couple of times ... I was breathing really loud and was trying not to, but I couldn't be quiet," she added.

Annapolis mayor Gavin Buckley said the community is grieving the attack on their community paper.

"These are the guys that come to city council meetings, have to listen to boring politicians and sit there," Mr Buckley said.

"They don't make a lot of money It's just immoral that their lives should be in danger."

New York police sent counterterrorism teams to news organisations around the city in a move authorities said was a precaution, not prompted by any specific threat.

Police could be seen outside The New York Times, ABC News and Fox News early in the evening.

Sign up to our free newsletters

Get the best updates straight to your inbox:
Please select at least one mailing list.

You can unsubscribe at any time by clicking the link in the footer of our emails. We use Mailchimp as our marketing platform. By subscribing, you acknowledge that your information will be transferred to Mailchimp for processing.