Thirteen people died after a gunman opened fire at a naval complex in the heart of Washington DC on Monday, in what became the worst attack on a military base in the US since the Fort Hood killings in 2009.

As authorities struggled to piece together the details of what happened at the Washington navy yard, Barack Obama lamented "yet another mass shooting" and called it a "cowardly act".

The FBI named the attacker as Aaron Alexis, a 34-year-old subcontractor and former reservist stationed in Texas until he was discharged in 2011. Police records showed that he had been arrested at least twice in the past for gun-related incidents.

Alexis died after a sustained firefight with police and security staff. "There were multiple engagements with the suspect who was ultimately deceased," said Cathy Lanier, chief of police in Washington DC. She said more people would have died had Alexis not been killed. "There is no question he would have kept shooting," Lanier said.

Law enforcement officials said Alexis was carrying three weapons during the rampage. Two federal officials said he had an AR-15 assault rifle, a shotgun and a handgun that he took from a police officer at the scene. The two officials spoke on the condition of anonymity because they were not authorised to discuss the investigation.

The computer firm Hewlett-Packard said Alexis worked for a subcontractor on a navy IT project. At a late-night press conference, the FBI said it was believed that Alexis used his contractor's badge to gain entry to the base. About 3,000 people work at the complex, which houses the US naval sea systems command headquarters, responsible for buying, building and maintaining the US navy's ships, submarines and combat systems.

There was no initial indication of a motive for the attack. John Kirby, the Navy's chief of information, said that after joining the navy in 2007, Alexis was assigned to a fleet logistics support squadron in Fort Worth. Official records show that he was arrested for a gun-related offence there in 2010.

Police in Seattle said Alexis, who was originally from New York, was arrested in 2004 in another gun-related incident. According to a statement by Seattle police, Alexis's father told detectives his son had "anger management problems" associated with post-traumatic stress disorder. He had been an "active participant in rescue attempts on September 11th, 2001," the Seattle police statement said.

Alexis was studying for an aeronautics degree via online classes at Embry-Riddle aeronautical university, the Associated Press reported. He had converted to Buddhism and wanted to become an ordained monk, friends said.

In the confusion after the attack, police initially feared two other men dressed in "military-style" uniform had been been involved, and launched a huge manhunt. They issued descriptions of two suspects, one said to have been a white man wearing a navy-style kahki uniform and carrying a pistol, the second described as black and wearing a drab olive military uniform and carring a rifle.

One of the suspects was quickly identified and ruled out of the investigation. The second was not eliminated from inquiries until later in the evening. At a 10pm press conference, police said the manhunt was over and lifted remaining restrictions on residents.

Doctors at the MedStar Washington hospital center said they were treating several victims. The chief medical officer, Janis Orlowski, said one police officer had multiple gunshot wounds to his legs and was undergoing complex surgery. His future ability to walk had yet to be determined, she said. Two other civilian patients were women: one shot in her shoulder, the other in her head and hand. The second woman's head wound was not serious: "She is a very, very, lucky young lady," Orlowski said.

On Monday night the Metropolitan police of Washington DC released an initial list of seven people killed. They were Michael Arnold, 59; Sylvia Frasier, 53; Kathy Gaarde, 62; John Roger Johnson, 73; Frank Kohler, 50; Kenneth Bernard Proctor, 46; and Vishnu Pandit, 61. Other victims' names were being withheld until family were notified, officials said.

Washington shootings map

Vincent Gray, the mayor of Washington DC, said he had no information to indicate that the attack was an act of terrorism. In a late-afternoon press conference, he confirmed that 13 people died, including the gunman. Police later said eight people had been injured.

The incident began at about 8.15am, in building 197 of the navy yard complex, when many people were having breakfast in the basement cafeteria. Some reports suggested that the gunman shot into the cafeteria from an overlooking walkway.

As multiple law enforcement agencies rushed to the scene, the naval yard and surrounding buildings were immediately placed on lockdown. With the suggestion that more gunmen were on the loose, security was tightened across Washington.

Speaking shortly after the attack, Obama said the victims had faced "unimaginable violence" and offered his condolences to their families. "We will honour their service to the nation they helped to make great," Obama said. The president, who has tried and failed to enact gun control measures in the wake of previous mass shootings, denounced the attack as cowardly.

Pentagon press secretary George Little added: "Everyone here at the Department of Defense is saddened by the incident at the Washington navy yard this morning. Our thoughts and prayers are with the victims.

"While the Pentagon remains open, the Pentagon Force Protection Agency increased its security posture, not out of a specific threat, but as a proactive, precautionary measure."

Though the motive for the attack remained unclear, it brought comparisons with the 2009 Fort Hood shooting, when Major Nidal Hasan, a psychiatrist at the Fort Hood base in Texas, killed 13 fellow service personnel in an attack that the army believes was carried out in response to US military involvement in Iraq and Afghanistan.

A lockdown remained in effect for hours after the shooting. Sailors and civilians assigned to the Washington navy yard, as well as all personnel assigned to the nearby joint base Anacostia-Bolling, were advised to stay put while authorities continued to investigate the scene.

In its statement, Hewlett-Packard said Alexis was employed by a subcontractor. The statement said: "Aaron Alexis was an employee of a company called 'The Experts,' a subcontractor to an HP Enterprise Services contract to refresh equipment used on the navy marine corps intranet (NMCI) network. HP is cooperating fully with law enforcement as requested."

Hewlett-Packard said it was "deeply saddened" by the incident. "Our thoughts and sympathies are with all those who have been affected," the company said.

On its website, The Experts, whose headquarters are in Alexandria, Virginia, describes itself as providing "innovative and mission-critical IT, engineering and litigation professional services for federal, state and local governments and departments".

It said in a statement: "The Experts would like to express our deepest condolences and sympathies regarding the incident that occurred at the DC naval yards. We are actively cooperating with the FBI and other authorities in relation to the investigation on the suspect."

On Monday night, officers from the New York Police Department cordoned off a section of the tree-lined street in the Bedford-Stuyvesant neighbourhood of Brooklyn, where family of Alexis lived in a brownstone apartment.

In what appeared to be an unconnected incident in a jittery Washington, a man was arrested outside the White House after throwing firecrackers over the north fence. Uniformed agents sealed off the area in front of the presidential mansion and ordered journalists inside. Police later identified the man as Alexander Sahagian and said he would likely face charges.