A former petty officer who apparently had a grudge against the Navy sprayed an office building with bullets at the Washington Navy Yard on Monday, killing 12 people in a rampage that paralyzed part of the nation's capital, authorities said.

Authorities said the gunman, a civilian contractor and former Navy reservist they identified as Aaron Alexis, 34, was killed after exchanging fire with officers who stormed the headquarters of the Naval Sea Systems Command in a massive law enforcement response.

D.C. Police Chief Cathy Lanier said Monday night that the suspect was believed to be the "single and sole" person responsible.

The gunman was armed with an assault-style rifle, a shotgun and a handgun when he was killed, authorities said. But law enforcement officials told NBC News they believed he arrived packing only the shotgun, which he bought last week from a gun dealer in Lorton, Va., about 20 miles from Washington.

Valerie Parlave, assistant director in charge of the FBI's Washington field office, said there was no indication of a motive on the part of Alexis, who she said had "legitimate" access to the complex.

Alexis worked for a subcontractor for Hewlett Packard Enterprises called "The Experts," which does work in the Navy Yard complex, according to a statement from Michael Thacker, HP's director of corporate media relations. He appeared to have an access card that would have allowed him onto the Navy Yard and other military installations, the company's chief executive, Thomas Hoshko, told The Washington Post.

D.C. police were identifying victims only after their families were notified. By late Monday night, they had named seven of the 12 victims:

John Roger Johnson, 73

Kathy Gaarde, 62

Vishnu Pandit, 61

Michael Arnold, 59

Sylvia Frasier, 53

Frank Kohler, 50

Kenneth Bernard Proctor, 46

Authorities said none of the victims were known to have been active-duty military personnel.

Eight other people were injured, D.C. Mayor Vincent Gray said — three with gunshot wounds, including a D.C. police officer, and five others with relatively minor injuries.

Dr. Janis Orlowski, chief medical officer at MedStar Washington Hospital Center, said the three gunshot victims were a woman who was hit in the head and hand; a woman who was hit in the shoulder; and the police officer, who was hit in the legs.

She said the victims came in alert, "talking about gunshots that they heard in rapid succession."

Orlowski described all three as doing relatively well. The police officer, who was in surgery for many hours, was most concerned about talking to his mother. He was stable Monday evening, officials said.

The woman hit in the shoulder was in such good spirits that she was playfully ordering doctors and nurses around. And as for the woman hit in the head, the bullet never penetrated her skull.

"She has a significant wound, but she will recover without surgery," Orlowski said. "She is a very, very lucky young lady."

Authorities earlier said they were looking for one person considered a possible suspect — a 50-year-old black man with a rifle, wearing an olive drab military uniform. Earlier they were looking for two people, but they found one and ruled him out as a person of interest, police said.

Besides being the deadliest U.S. shooting rampage since the Sandy Hook Elementary School massacre in December, when 20 children and six adults were killed in Newtown, Conn., Monday's spree was the deadliest on a U.S. military installation since 13 people were killed at Fort Hood, Texas, in 2009.

President Barack Obama called it a "cowardly act." Speaking at an event marking the fifth anniversary of the financial crisis, he turned to the shooting and said: "We are confronting yet another mass shooting, and today it happened on a military installation in our nation's capital."

The Navy said the first shots were fired at 8:20 a.m. ET at the Sea Systems Command headquarters.

Patricia Ward, who works at the Navy Yard, said she had just gotten breakfast in the cafeteria when she heard "three gunshots, pow-pow-pow, straight in a row."

"All of the people that were in the cafeteria, we all panicked, and we were trying to decide which way we were going to run out," she said. "I just ran."

The roughly 3,000 people who work there were told to stay in place. For the next several hours, conflicting reports circulated about whether the shooter was still alive, whether he had accomplices, how many places were active shooting scenes and how many people were dead and injured.

In the meantime, chaos enveloped the surrounding neighborhood. Flights were briefly grounded at Reagan National Airport. Nearby schools and bridges and the headquarters of the Transportation Department were locked down. Farther away, police stepped up security on the Capitol grounds.

Terrie Durham, who works at the Naval Sea Systems Command building, said she saw a gunman who appeared to be wearing dark fatigues. Another worker there, Todd Brundidge, said he heard a fire alarm go off and later saw the gunman come around the corner.

"He turned our way and started firing, and we ran downstairs to get out of the building," Brundidge said. "No words. He raised the gun and started firing."

Brian Chaney, who works on the second floor, described it as a typical Monday. He said he took the stairs toward his office and heard what he thought was a locker door slamming. He later heard another round of what turned out to be gunshots.

A naval security guard was shot in both legs, U.S. military officials said. Lanier said a city officer, Scott Williams, was also among those shot. It wasn't clear how many of the others shot were civilian and how many were military.

Suspect's family bewildered and distraught

It also wasn't clear exactly how Alexis died. He lived in the Queens borough of New York a decade ago and is still listed on voter rolls there. A Navy spokeswoman said Alexis served from May 2007 through January 2011 and was an aviation electrician's mate — a third-class petty officer — before he was discharged.

The spokeswoman had no details on the discharge.

NBC New York confirmed that some of Alexis' relatives — including his mother, Cathleen Alexis — live in Brooklyn.

Anthony Little, Alexis' brother-in-law, told NBC New York that his family was "distraught" in the wake of the shooting. He said Alexis' mother was being questioned by the FBI.

Authorities initially filed charges, but those charges were later dropped — therefore not preventing Alexis from passing a federally-required criminal background check, an official said.

In Fort Worth, Oui Stuhamtewakul, who identified himself as Alexis' best friend and former roommate, described Alexis as a Thai speaker.

Oui, the owner of a Thai restaurant in Fort Worth, said Alexis owned a gun and had a concealed-weapons permit. He said they were last in touch four months ago, when Alexis left for Washington.

Alexis had been treated multiple times for psychological issues — including sleep deprivation, anger and paranoia — sources told NBC News. Most recently, sources said, he had been treated at an unspecified Veterans Affairs hospital in New England.

Bill Bratton, the former police commissioner of Boston and New York and former chief of the Los Angeles police, said responders likely acted quickly after getting reports of shorts fired.

"At the beginning" of this kind of shooting scenario, "you try to get your arms around what's going on (and) close off the perimeters as quickly as you can to prevent the suspects from fleeing," said Bratton, a criminal justice analyst for NBC News.

Although the FBI believes it knows a great deal about Alexis, investigators were nonetheless asking for information about him. Officials released a poster Monday afternoon with Alexis' photo and relevant numbers to call.

At the direction of House Speaker John Boehner, all House flags will be lowered to half-staff until sundown Friday. Obama has also ordered that flags fly at half-staff at the White House.

The Naval Sea Systems Command builds, buys and maintains ships and submarines and their combat systems. The Navy Yard is along the Anacostia River in Washington, near the Washington Nationals' baseball stadium. The Nationals postponed their game Monday night against the Atlanta Braves. The notation on the Nationals' website read, "Postponed: Tragedy."