The suspected coup plotters stormed the state radio and television headquarters around 4 a.m. Monday, allegedly taking journalists and staff hostage, while they read out a statement saying they had taken control of the Central African nation.
The officers declared their dissatisfaction with President Ali Bongo and said they had seized power to "restore democracy" in the country.
The two officers were killed when Gabonese defense and security forces moved in to stop the takeover and rescue the hostages, state-run Agence Gabonaise De Presse (AGP) reported on Tuesday.
Four soldiers were arrested a few hours after the coup attempt, government spokesman Guy-Bertrand Mapangou said.
A fifth officer, identified by Mapangou as Lt. Kelly Ondo Obiang, was captured hiding in a building beside the radio station, Mapangou told CNN.
On Monday, Mapangou told French news outlet RFI that defense forces have now taken back control of state TV and radio.
"It seems it was a group of troublemakers because military officials say they weren't aware of this group," Mapangou said.
The government in Gabon also said the "situation is under control" and peace had been restored to the capital.
A video circulated on social media Monday showed several officers in a radio studio dressed in military fatigues.
A man who described himself as commander of the Republican Guard and president of the Patriotic Movement of the young security forces of Gabon said in a lengthy statement that there has been a decline in the President's health and in his presidential capacities. As two men dressed as officers stood behind him with guns, the man said that the Patriotic Movement would preserve the integrity of the nation.
The officer said they were disappointed by Bongo's message on December 31 from Morocco, where he is recovering from a stroke.
Bongo has been battling ill health since October and acknowledged the speculation about his health during his New Year's speech, but insisted he is recovering.