A generalization of a theorem of Nagell