The soldiers guarding the compound were killed and six insurgents died in the assault.
Officials also said an apparent Nato airstrike had killed 15 people - nine of them civilians, including women and children - in a remote eastern province where the Taliban are strong.
Nato said 10 militants died in the strike but it had no news of any civilian deaths.
Both incidents underscored the insecurity in Afghanistan as US-led foreign forces reduce their presence and hand over more responsibilities to Afghan troops.
Yesterday's bombing occurred in Maidan Shahr, a city in eastern Wardak province that lies just 25 miles from Kabul.
The powerful explosion shattered windows across a wide stretch of the city.