A gunman killed a dozen people as the workday began at the Washington Navy Yard on Monday, creating an improbable moment of horror at a military facility with armed guards at every gate and leaving investigators seeking clues about what spurred the attack.

The FBI identified the shooter as Aaron Alexis, 34, of Fort Worth, who in 2011 received a general discharge from the Navy Reserve, a designation that usually signals a problem in his record. Alexis was arrested but not charged in a gun incident in Seattle in 2004 but still had a security clearance with a military contractor that allowed him access to the Navy Yard, officials said.

The suspect died when the mayhem ended in a gun battle with police. Late Monday night, authorities began releasing the names of those killed in the rampage, but some family members were still awaiting word about loved ones. The dead ranged in age from 46 to 73 years old.

The shootings constituted the worst loss of life in a single incident in the region since the Sept. 11, 2001, attack on the Pentagon killed 184 people.

“This is yet another heartbreak for our city,” said Del. Eleanor Holmes Norton (D-D.C.).

Alexis left Texas about a year ago, and authorities made a public appeal Monday for help in tracing his movements since then. They said they believe he entered the Navy Yard with a valid badge and had been in the Washington region for about four months, working as an hourly employee with a defense contractor.

“We don’t know what the motive is,” said D.C. Mayor Vincent C. Gray (D). The mayor said there was no reason to suspect terrorism. Other officials said they do not know whether Alexis’s discharge played a role in the shootings but said that is one line of inquiry.

The shooting began about 8:15 a.m., when the echo of gunfire behind the walled security of a military base stunned people arriving to begin their workweek. The sprawling base on the Anacostia River has 16,000 military and civilian employees .

“I didn’t believe it,” said Alley Gibson, 28, who works in Building 197, were the shootings took place. “At first I was in shock. Nothing like this ever happens — especially not on a base. It’s just not normal. It’s wild — it’s like a movie.”

As people scattered for cover, they turned to text messages and office televisions in an effort to determine what was going on.

“We were sort of in the dark,” said John Norquist, 52, a Fairfax lawyer who served as a civilian adviser in Afghanistan last year. “We were trained in active shooter scenarios.”

The full weight of Washington’s vast anti-terrorism network converged on Southeast Washington within minutes of the first shots as local and federal law enforcement teamed to sweep the Navy Yard and the surrounding neighborhood.

The shootings threw the nation’s capital into turmoil, with police fearful that two other gunmen might be on the loose. By late Monday, D.C. Police Chief Cathy L. Lanier said investigators were confident that Alexis was the only gunman.

Throughout the day, people were warned to remain in their homes and those at offices on the naval base and in the surrounding neighborhood were told to stay put.

Flights were briefly halted at Reagan National Airport. Schools near the base were locked down. The Senate adjourned early, and people were not allowed to enter or leave much of the Capitol complex. The ripple of snarled traffic spread beyond closed streets in Southeast Washington to infect travel elsewhere.

“This has been a dark day,” said House Speaker John A. Boehner (R-Ohio).

The Washington Nationals, whose ballpark is close to the base, were told to stay away from their stadium during the search. A critical game against the division-leading Atlanta Braves was postponed until Tuesday. The official Major League Baseball description of the game was stark: “Postponed: Tragedy.”

Investigators said Alexis shot a security guard at Building 197, most likely with a shotgun he bought in Lorton in Fairfax County. He took the guard’s handgun before moving methodically through the interior, they said.

He shot 15 people, 12 fatally, and injured five others before he died, investigators said.

Authorities on Monday night released the names of seven of those who were killed: Michael Arnold, 59; Sylvia Frasier, 53; Kathy Gaarde, 62; John Roger Johnson, 73; Frank Kohler, 50; Vishnu Pandit, 61; and Kenneth Bernard Proctor, 46. The Washington Post confirmed the identity of an eighth person, Arthur Daniels, 51.

Among those injured was a D.C. police officer who was shot twice in the leg. The officer, Scott Williams, a 23-year veteran, and the other injured victims all are expected to survive.

“There’s no question he would have kept shooting,” said Lanier, who declined to say how many shots were fired from start to finish. Police said Alexis also had an assault rifle inside the building, but it was unclear whether he had brought it with him.

It took a series of shootouts to bring Alexis down, officials said. Active shooter teams engaged him several times before at least two officers — one from D.C. police and one from U.S. Park Police — fatally wounded the suspect, they said.

Perplexing to those as the event unfolded around them, and puzzling to investigators in the aftermath: How did a man with a shotgun pass through one of three gates where Marine and Navy security personnel screen all visitors?

“I don’t think we know that,” said Valerie Parlave, the assistant FBI director in charge of the D.C. field office. “The investigation is still very active.”

Several former military officers who work in the building said that there are armed guards at the main entrance and that employees must scan an access card. But two people who work there said those with properly coded cards can enter through a side door from a garage, bypassing the security guards.

Alexis had been working much of this year as a computer contractor for a company called The Experts and appeared to have a government-contractor access card that would have allowed him into the Navy Yard and other military installations, according to company chief executive Thomas Hoshko.

Alexis had a security clearance that was updated in July, approved by military security service personnel.

“There had to be a thorough investigation,” Hoshko said. “There is nothing that came up in all the searches.”

The FBI took charge of the case later in the day, with President Obama promising a “seamless” investigation that coordinated D.C. police and the myriad law enforcement agencies that responded to the incident.

“This is a safe city, and we should go about our business,” Norton said. “The facility itself is one of the most secure facilities in the District.”

But for those inside the Navy Yard when the shooting occurred, it was a day of terror and uncertainty.

“It’s unbelievable that someone could get a rifle in there,” said David Stevens, a Navy contractor who was on the third floor of Building 197 when the shooting began.

He ran to the edge of a glass atrium that overlooks all the floors and glanced up. He could not see anything but heard a “second deluge” of shots — perhaps six.

One floor below Stevens, another contractor, Paul Desbiens, said the first thing he heard was the fire alarm, which went off around 8:30 a.m. He realized something more serious was going on as he and others encountered police at the building’s entrance.

“They didn’t say what was going on,” Desbiens said. “They just said, ‘Run!’ ”

Vice Adm. Bill French, the head of all Navy installations, said late Monday that about 2,000 civilians remained at the Navy Yard and that it could take until 11 p.m. or later to finish processing them off the base.

Removal of the employees was painfully slow because the FBI was still interviewing every person leaving the base, out of concern that a second suspect might still be at large.

SWAT teams were still finding people hiding in places on the base, where they had remained hunkered down since early morning. One city official said that shortly before 7 p.m., officers found an employee hiding in a locker, where he had been for nearly 11 hours.

Navy Undersecretary Juan Garcia said the Navy Yard would reopen Tuesday for essential personnel only. Most employees would be encouraged to telecommute. Garcia said it was unclear when the base would reopen in its entirety.

It was the second mass shooting in recent years inside the secure confines of a military base, coming after Army Maj. Nidal Hasan killed 13 people and injured more than 30 in 2009 at Fort Hood in Texas.

The Navy Yard shooting marks the seventh time in the past decade that a gunman has killed 10 or more people in a single incident. The most notable incidents were the 2007 Virginia Tech shooting in which 32 died; the Aurora, Colo., movie theater shooting last year in which 12 were killed; the Newtown, Conn., school shooting last year in which 26 were killed; and the 2009 Fort Hood rampage.

Correction: The headline on a previous version of this article misstated the number of casualties. This version has been corrected.