Tragedy nearly struck a plane flying from Manchester to Funchal, Madeira, when the pilot reportedly passed out mid-flight.

Fortunately, an off-duty pilot was apparently flying on the same plane and was able to step in. The plane was then forced to make an emergency landing at Porto Airport in Portugal.

The incident occurred on a Jet2 flight on Monday morning, The Sun reports. An alarm was reportedly sounded around 10:20 a.m. and a runway at Porto airport was closed until about 11 a.m. to keep it available for the emergency landing.

Jet2 confirmed on Twitter that an “onboard medical situation” occurred on flight LS765 from Manchester to Funchal. They posted, “We would like to apologize to customers traveling on #LS765 from Manchester to Funchal, Madeira which has diverted into Porto, Portugal due to an onboard medical situation. We are working to get you on your way ASAP. Please see our agents ‘Portway’ at Gate 2 for more info.”

UNITED AIRLINES PLANE TURNS AROUND MID-WAY TO HAWAII DUE TO MECHANICAL ISSUE: REPORT

In a statement obtained by Fox News, a spokesperson for Jet2 said, “Flight LS765 from Manchester to Funchal diverted to Porto as a precautionary measure this morning, due to one of the pilots feeling unwell. A standby aircraft and replacement crew will be flown to Porto so that we can get customers on their way to Funchal as soon as possible.”

CLICK HERE TO SIGN UP FOR OUR LIFESTYLE NEWSLETTER

A man who said he was a passenger on the flight said that the original pilot was wheeled off the plane in a wheelchair and wearing an oxygen mask, The Sun reports.

CLICK HERE TO GET THE FOX NEWS APP

According to a follow-up Tweet from Jet2, it appears that at least some passengers were booked on a flight scheduled to take off around 7:50 p.m. local time.