Two Afghan military officials were jailed for 20 years after a two-year trial for sharing state secrets with Pakistan, a prosecutor said on Wednesday.