“I heard three gunshots, pow, pow, pow, straight in a row,” said Patricia Ward, a logistics management specialist from Woodbridge, Va., who was in the cafeteria on the first floor when the shooting started. “About three seconds later, there were four more gunshots, and all of the people in the cafeteria were panicking, trying to figure out which way we were going to run out.”

Police officers who swarmed the military facility exchanged fire with a gunman later identified by the federal authorities as Aaron Alexis, 34, a former naval reservist from Fort Worth, Tex. Police officers shot and killed Mr. Alexis, law enforcement officials said, but not before a dozen people were killed and several others, including a police officer, were injured and taken to local hospitals.

Officials said Mr. Alexis was able to drive onto the base and began firing as he approached Building 197, shooting an officer. Once inside, Mr. Alexis made his way to a floor overlooking an atrium and took aim at the employees eating breakfast below.

“He was shooting down from above the people,” one law enforcement official said. “That is where he does most of his damage.”

A police officer underwent several hours of surgery for gunshot wounds to his legs. A second victim suffered a gunshot wound to her shoulder. A bullet grazed a third victim’s head but did not penetrate her skull, according to doctors at MedStar Washington Hospital Center.

Three weapons were found on Mr. Alexis: an AR-15 assault rifle, a shotgun and a semiautomatic pistol, a senior law enforcement officer said. Officials said they were still searching for a motive as they asked the public for help by posting pictures of Mr. Alexis on the F.B.I. Web site.

Navy officials said late Monday that Mr. Alexis had worked as a contractor in information technology. A spokesman for Hewlett-Packard said Mr. Alexis had been an employee of a company called The Experts, a subcontractor on an HP Enterprise Services contract. Navy officials said Mr. Alexis was discharged in 2011 after exhibiting a “pattern of misbehavior,” which officials declined to detail. Because of the lockdown at the Navy Yard, the officials said they were still unable to search databases to determine his current employment status, or whether he had been fired.

The police in Seattle, where Mr. Alexis once lived, said Monday that they had arrested him in 2004 for shooting the tires of another man’s vehicle in what Mr. Alexis later described to detectives as an anger-fueled “blackout.”

Eleanor Holmes Norton, the Congressional representative for the District of Columbia, called the episode “an attack on our city.”

“It’s an attack on our country,” she added.

Mayor Vincent C. Gray called it a “long, tragic day.” President Obama praised the victims of the shooting as patriots.

The tension in the city was heightened for much of the day as the city’s police said they were still unsure whether Mr. Alexis had acted alone. Officials said surveillance video of people fleeing the scene of the shooting showed two armed men dressed in different military uniforms and wielding guns. For hours, the police said they believed that there might have been three gunmen and that two of them were on the loose in the city.

Officials later cleared one of the two men seen on the surveillance video. They continued to search for an African-American man about 50 years old who was wearing an olive-colored military-style uniform and was believed to be carrying a “long gun.”

The reports of multiple suspects generated confusion across Washington as the authorities offered conflicting messages about any continuing danger. Officials did not move to secure the city, leaving the city’s subway system to operate normally. But out of an “abundance of caution,” Terrance W. Gainer, the Senate sergeant-at-arms, put the Senate complex into lockdown at after 3 p.m. The Senate had recessed in the early afternoon.

Around the same time, the Washington Nationals postponed a game against the division-leading Atlanta Braves, which had been scheduled for 7 p.m. at Nationals Park, next to the Navy Yard. The Nationals’ Web site said “Postponed: Tragedy” and notified fans that the teams would play a doubleheader on Tuesday instead.

A city already on edge was further shaken Monday evening when someone tossed firecrackers over the fence at the White House, causing loud bangs and prompting a swift and aggressive response from Secret Service agents, who tackled a man in white shorts and a T-shirt on Pennsylvania Avenue Monday morning, the shooting started at 8:20 on a drizzly day at the Navy Yard, which sits at one end of the 11th Street Bridge, a major thoroughfare bringing traffic into the city from Maryland.

Within minutes of the first reports of shots, hundreds of police officers and naval officers surrounded the Naval Sea Systems Command headquarters, where about 3,000 service members, civilians and contractors work on the Navy’s fleet. Military helicopters circled the facility as police vehicles and other emergency vehicles rushed to the Navy Yard. A helicopter lowered a basket to the roof of one of the buildings and appeared to be taking away victims.

One victim, described as a man in his 60s, was shot in the left temple and was pronounced dead within a minute of arriving at George Washington University Hospital. “This injury was not survivable by any stretch,” a hospital official told reporters. “The patient was dead on the way to the hospital.”

Investigators were still trying to determine how Mr. Alexis gained access to the Navy Yard. The site is protected by a high wall, with entry through checkpoints that require official identification. However, under the “force protection status” that was believed to have been in effect early Monday, someone with official access to the site could have driven a car into the parking lot without having the trunk inspected, or could have entered on foot without having a bag searched.

Employees evacuated from the building described a chaotic situation as an individual armed with a rifle roamed the hallways shooting at people.

Commander, Tim Jirus said he was on the fourth floor when he heard gunshots and saw people start running through the office. The commander said he was at the back of the building working to get people out when a man came out of a maintenance building and approached him, asking about the shooting. Moments later, the man, a civilian, was shot in the head, he said.

“We had a conversation for about a minute,” Commander Jirus said. “I heard two gunshots, and he went down, and then I ran back here.”

Holding a radio as he waited outside the Navy Yard Metro station, Commander Jirus said he had heard that another man in his office, also a civilian, had been shot and evacuated to a hospital.

Asked how he escaped when the man next to him was shot, he said: “Luck. Grace of God. Whatever you want to call it.

The grace of God has nothing to do with luck, and everything to do with is mercy.

We must pray that he keeps is covered so that our families and friends don't fall victim to the next maniac......and so we wait.