Minutes before the grenade attack, two people reportedly died after police opened fire in the same market.
Eyewitnesses said the grenade was thrown at a group of policemen, one of whom was killed along with a bystander.
One other person was killed after another police officer on the scene opened fire.
Darwish said the curfew was necessary to restore security to the capital.
"We need our forces to tackle the violence in the evenings and secure the city in order to prevent explosions"
Mohamed Warsame Darwish, head of Somalia's national security agency
"We need our forces to tackle the violence in the evenings and secure the city in order to prevent explosions. That is why we are imposing the curfew," Darwish said.
Police last week set an overnight curfew in the central town of Baidoa after grenade attacks in a cinema and a bank killed at least three people and wounded at least 12.
Violence has continued in Mogadishu despite Somali government troops backed by Ethiopian forces pushing opposition fighters, led by the Union of Islamic Courts (ICU), from the capital.
Months of fighting has left hundreds of civilians dead and hundreds of thousands displaced.
In recent months, opposition fighters have targeted government officials, Ethiopian troops and African Union (AU) peacekeepers in the country.
Last week, a UN-backed peace conference bringing together Somali clan leaders and government officials was postponed for the third time.
Somalia has been without a functioning central authority since ruler Mohamed Siad Barre was deposed in 1991.
The current transitional government, now nearly three years old, has been unable to maintain security in Somalia.