In an arbitrary Lorentzian manifold, we fix a spacelike submanifold P and a timelike submanifold Γ. We interpret P as (the surface of) a light source at a particular instant of time, and we interpret Γ as the history of (the surface of) a receiver. We prove the following version of Fermat's principle. Among all lightlike curves from P to Γ, the lightlike geodesics which are perpendicular to P and spatially perpendicular to Γ are characterized by stationary arrival time. Here, the arrival time is defined with the help of an arbitrary time function on Γ. Moreover, we show that the second variation of the arrival time at a stationary point is characterized by a Morse index theorem.