ANNAPOLIS, Md. — Five people were killed Thursday afternoon in a shooting at the Capital Gazette newsroom in Annapolis, Md., and several others were “gravely injured,” said William Krampf, acting chief of the Anne Arundel County Police Department.


The suspected gunman, a white adult male, used a shotgun in the attack, according to a law enforcement official. The suspect is in custody and is being interrogated, said Steve Schuh, the county executive, and there was no information on motive as of late Thursday afternoon.


More than 170 people were in the building at the time, Mr. Krampf said at a news conference.


The suspect did not exchange gunfire with officers when he was taken into custody, said Lt. Ryan Frashure, a police spokesman.


Phil Davis, a reporter at the newspaper, said on Twitter that a “gunman shot through the glass door to the office and opened fire on multiple employees.”


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


Anthony Messenger, a summer intern at the newspaper, wrote on Twitter at 2:43 p.m.: “Active shooter 888 Bestgate please help us.”


Anne Arundel Police confirmed that the building had been evacuated and that officers were searching it.


Aerial video showed a heavy police presence, as well as lines of people with their arms up in the air walking away from the area.


Jahnae Miller, 23, a teacher from Hyattsville, said she was at her doctor’s office on the first floor of the building when nurses and other workers started shouting to turn off the lights because there was a shooter down the hall. They turned off the lights, and she hid under a desk in an inner room for about an hour. They barricaded the doors with filing cabinets that the police had to push out of the way to get inside.


“I was afraid, I was crying,” she said. “I teach elementary school, and lockdown drills have become normal, unfortunately. To be in a situation — that it’s not a drill this time. To feel those emotions going through and not knowing where the shooter is, it was kind of overwhelming.”


The building is mixed use with various offices, including those of a pediatric orthodontist and a lawyer.


The episode prompted the New York Police Department to deploy counterterrorism teams to news media organizations in and around New York City, a decision that has become standard practice during terrorist and active shooter events. The latest deployments were not based on a specific threat, the N.Y.P.D. said in a statement, but rather “out of an abundance of caution until we learn more about the suspect and motives behind the Maryland shooting.”


Mayor Gavin Buckley of Annapolis sent “love and thoughts to all the families who’ve been affected by this.”


He commended the emergency workers, who he said had recently run through active shooter training. “We did not expect something like this to happen in our community, but we were ready,” he said.


Gov. Larry Hogan of Maryland said he was “absolutely devastated to learn of this tragedy.”


President Trump said on Twitter that he had been briefed on the shooting. “My thoughts and prayers are with the victims and their families,” he said.


The Capital Gazette’s website directory lists 55 newsroom and business-side employees.


Capital Gazette Communications publishes a daily newspaper, as well as a website and other papers serving other local areas. It is owned by the Baltimore Sun Media Group. The company, one of the oldest publishers in the country, was founded in 1727, according to its website.


Carlos Linares, 70, a mechanical engineer, was in a conference room at a law firm on the fourth floor when the shooting began.


He heard “some loud noise, loud footsteps, a commotion that you usually don’t hear in a lawyer’s office,” he said. “I thought, that’s strange.”


He stepped out and saw that “everyone was huddled in the front lobby,” he said. Several of the men and women were upset and agitated, he said. He was told that there was an active shooter on the first floor.


He and the others were escorted out of the building about 30 minutes later, and led across the street to the Annapolis Mall to the Lord & Taylor store, where people in the area were being reunited with their families.


It was only when he saw all the police officers, SWAT team and bomb squad that Mr. Linares realized the extent of the shooting. “I didn’t know how big it was,” he said. “I had never seen so many police in my life.”


This is a developing story and will be updated.


JoAnna Daemmrich contributed reporting from Annapolis, and Julia Jacobs from New York.