This was during rush hour on Wednesday, a police spokesman said.
It was not immediately clear what caused the blast. Two witnesses at the scene said it shattered the glass of nearby stores and sent plumes of smoke billowing into the air.
The explosion rocked an area near the popular Banex Plaza shopping centre in the upscale Wuse 2 district, they said.
“After a preliminary investigation, we can confirm that 21 people were killed and 17 injured,” police spokesman Frank Mba told reporters at the scene of the explosion.
“I heard a loud blast, it shattered the windows of the shop. We ran out. A lot of people ran too, some with blood stains,” said Gimbya Jafaru, who was shopping nearby.
The blast came as the area was packed with shoppers and rush-hour commuters, an emergency services source said.
“This thing happened at a peak period,” the source said, estimating that around 40 cars had been badly damaged.
Soon after the blast, emergency services were on the scene and the police and army had blocked off the surrounding area, a Reuters reporter on the scene said. A haze of smoke lingered over the area as the bomb squad combed the area for explosives.
Separately, a roadside bomb blew up in the northeastern Adamawa state, although no one was injured in that explosion, local police spokesman Othman Abubakar said
Nigeria has been hit by almost daily bomb and gun attacks, which are widely suspected to be the work of Islamist militant group Boko Haram.
The insurgents, who are trying to carve out an Islamist state in the north, have been increasingly moving beyond their traditional base in rural northeast Nigeria.
Abuja has been a target for bomb attacks in recent months. A suspected car bomb in May killed at least 15 and an attack on a bus station a month earlier killed at least 75.