Pakistan has accused militant groups based in Afghanistan of carrying out attacks and infiltration attempts, which Kabul has denied.