Your model must shoot at the closest enemy because he represents the most immediate threat and therefore the most obvious target. However, he may shoot at a more distant target if it is easier to hit or if closer models are stunned or knocked down (see the diagram below).
For example, a closer target may be hard to hit because it is in cover, whilst a more distant target might be in the open and therefore an easier shot.
Your model can shoot at models that are fleeing, knocked down or stunned, but he can choose to ignore them, because they do not represent an immediate threat. It is better to shoot the closest standing enemy model instead.
Note that your model may not shoot at models engaged in close combat, as the risk of hitting his comrades is too great.