Among the dead were two policemen, he said.
The attack was meant to frighten Afghans, but the perpetrators would not succeed, he said.
The attacker set off his explosives before passing through a police screening post, suggesting that he may have triggered the bomb after a policeman spotted it. Rahim said three policemen were killed.
However, Public Health Ministry spokesman Wahid Majroh disputed the number, saying the suicide bombing claimed 10 lives and wounding 22 others.
Kazim Ali, who was at the gathering, told AFP the force of the explosion shattered the windows of the mosque.
The overnight Taliban attack in northern Takhar Province took place in a remote region of the district of Khwaja Ghar. "We are engaged with Pakistan on how we can work together as well as address Pakistan's legitimate concerns through a negotiated process", she said.More news: Noble defends reaction to West Ham pitch invader
In December, dozens of people were killed in a suicide attack on a Shi'ite cultural centre claimed by Islamic State, and two months earlier two separate mosque attacks killed at least 72 people.
Yamamoto stressed that President Ashraf Ghani "offered peace to the Taliban without preconditions, and laid out a path for negotiations with ... concrete proposals". The insurgents launched a siege of an army outpost there, killing six soldiers and wounding five in a blistering, hourslong battle, Defense Ministry spokesman Dawlat Waziri said.
Ghani at an global conference in Kabul last week unveiled a plan to open talks with the Taliban, including eventually recognizing them as a political party.
In return, the militants would have to recognize the Kabul government and respect the rule of law.
"The offer of negotiation is on the table", United Nations envoy to Afghanistan Tadamichi Yamamoto told a Security Council meeting on Thursday to mark the annual renewal of the United Nations mission to the war-torn country.
Before Ghani's speech, the militants had called for direct talks with the US.