A bomb exploded in a mosque in eastern Afghanistan during Friday prayers, officials said, killing at least 29 men who had gathered for worship.