The militant Islamist group al-Shabab said one of its fighters carried out the attack.
Casualties have been reported, but details are unclear.
Government troops and African Union forces took Afgoye from al-Shabab in May. It had been one of the group's major strongholds.
The town is about 30km (18.5 miles) from the capital, Mogadishu, on a road linking the city with rebel-held areas in the south of the country.
Despite facing pressure on a number of military fronts, al-Shabab still controls much of the country.
Somalia has not had an effective central government since 1991.
Pro-government forces took control of Mogadishu in August last year.