"Around 5 am, two Pakistani terrorists in Afghan police uniforms armed with AK-47s and pistols wanted to carry out an attack on Afghan worshippers 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.
Three Afghan worshippers were wounded by the Pakistanis and taken to hospital, the statement added.
Afghan officials often accuse the Pakistani government and its intelligence agents of sheltering insurgents and supporting them in attacks in Afghanistan -- allegations that Pakistan denies.
Around 87,000 US-led NATO troops are to leave Afghanistan next year, putting Afghan forces in charge of nationwide security.