The National Directorate of Security said the attackers, disguised in police uniform, were armed with AK-47 rifles and pistols when they attacked in west Kabul.
"Two Pakistani nationals who were members of Lashkar-e-Jhangvi had orders from their masters to carry out brutal attacks on worshippers in the mosque in west Kabul," it said in a statement.
"Fortunately, the two terrorists were shot dead by Afghan intelligence forces in an exchange of fire," it added.
Lashkar-e-Jhangvi is one of Pakistan's most violent anti-Shiite militant groups and has links to al-Qaeda. It has been blamed for multiple attacks targeting Shiites.
More From This Section
The Afghan intelligence agency statement also accused "certain known circles" within Pakistan's Inter Services Intelligence spy agency of trying to stoke sectarian violence in Afghanistan.
Kabul officials often accuse the Pakistani government and its intelligence agents of sheltering insurgents and supporting them in attacks in Afghanistan -- allegations that Pakistan denies.
President Hamid Karzai last week spent two days in Pakistan, asking its new government to help set up peace talks between his administration and Taliban insurgents.