The group of about 50 attackers, armed with assault rifles, grenades and rocket launchers, battled with security forces for an hour.
A dozen people, including police and civilians were injured, some seriously.
Officials say araound 50 people have been arrested, and arms and ammunitions seized.
The fighting was the worst in the Cambodian capital since the violent 1997 removal of Prince Norodom Ranariddh by Prime Minister Hun Sen.
Police linked the gunmen to the anti-Communist Cambodian Freedom Fighters, which accuses the government of being a Vietnamese puppet.
Grenades
The attack started at around 0100 (1800 GMT Thursday), after the men arrived in the city from the nearby train station.
Reports say between 30 and 40 men threw grenades and exchanged fire with soldiers and police outside the Ministry of Defence.
Another group launched a simultaneous assault on a military barracks some 15km (nine miles) west, on the outskirts of the capital, according to a senior military official.
He said the barracks, which is responsible for the security of top government officials, had been struck by rocket-propelled grenades.
Police said the seven killed in the fighting were all rebels.
Military Police General Chhin Chanpor went on national radio to assure the country that the authorities had re-established control.
"We already know who is behind this and we have arrested one of their top leaders," he added.
"I do not think these people are involved in politics. They are armed terrorists aiming at destroying national security "
Security forces are sweeping through the city in a mop-up operation.
Prime Minister Hun Sen is currently out of the country attending the Association of South-East Asian Nations meeting in Singapore.