A gunman opened fire at Joint Base Pearl Harbor-Hickam near Honolulu on Wednesday afternoon, killing two and injuring a third before shooting and killing himself, base officials said.

The shooter was identified as an active-duty U.S. Navy sailor and the three victims as civilian Defense Department employees working on the base’s shipyard. The surviving victim is at a hospital in stable condition, Rear Adm. Robb Chadwick said in a Wednesday evening news conference.

The shooter’s motive is still unknown, Chadwick said, and it wasn’t yet clear whether the attack was targeted or random.

The violence unfolded about 2:30 p.m. local time near one of the shipyard’s four dry docks, where vessels typically undergo repairs. The gunman, who has not been identified, was assigned to the USS Columbia, a submarine receiving maintenance at Dry Dock 2, where the shooting occurred, Chadwick said.

Within minutes, the base’s security officers were on the scene, as were members of the Honolulu police and fire departments. All access points and gates were shuttered, and the base was placed on lockdown, officials said. Nearly two hours later, the base announced it had reopened its gates.

Late Wednesday, base officials had not yet identified the victims but said all involved were male.

Chadwick described a close-knit community on and around the base, using the Hawaiian word “ohana” to explain the relationship among locals, members of the military and others who work on the base.

“This is certainly a tragedy for everyone here,” he said.

The shipyard is located on the base but also employs civilians, a Honolulu city official said, adding that bystanders probably belonged to one of three groups: active-duty military personnel, members of their families and civilian dock workers.

Though the dry dock is near several military memorials, it’s unlikely that tourists would have been present, the official said.

“We share in the sorrow of today’s tragic shooting at the Pearl Harbor Naval Shipyard and are thankful for the actions of our federal and state partners, as well as the city’s first responders who rushed to the scene,” Honolulu Mayor Kirk Caldwell said in a statement.

Elena Gartland was driving off the base about 2:30 p.m. after attending a cookie-decorating class for officers’ spouses when she said the traffic abruptly stopped. Several police cars and firetrucks drove by the hundreds of idling vehicles, and an active-shooter warning played over loudspeakers on the base.

“All I could make out was ‘Secure in place,’ ” Gartland, 30, told The Washington Post. “There were lots of police sirens around us at the time of the announcement.”

Motorists got out of their cars and commiserated for two hours before being allowed to drive on, Gartland said.

The base abuts Daniel K. Inouye International Airport in Honolulu, on the island of Oahu’s south shore. The shipyard is located near the Pearl Harbor National Memorial, which commemorates the bombing by Japanese forces that pushed the United States into World War II. Saturday marks the 78th anniversary of that attack.