When the copilot of a Lufthansa flight was struck with a debilitating migraine while mid-air on Monday, the crew could have used a doctor -- but what they got was a pilot.

Luckily, one brave passenger happened to work for North American Airlines, making him fully qualified to fly commercial aircraft.

"It was a miracle," a source involved in the operation told Independent.ie. "It had all the elements of a Hollywood movie but thankfully one with a happy ending."

Shortly after the copilot took ill, the staff announced they were diverting the 747 to the Dublin airport, according to AOL UK. The flight, which carried 264 passengers, was originally scheduled to journey from Newark to Frankfurt.

The passenger, who the Daily Mail said remains unidentified but may have been a German man, asked the reason for the diversion, then offered assistance. Just before 6 a.m., he helped bring the plane to a safe landing in the Irish capital.

A spokesperson for Lufthansa told the Irish Examiner that if the pilot hadn't been on board, the crew would have managed the incident themselves, building on their required training for emergencies that occur on board. But the airline is branding the helpful man a hero anyway.

"Lufthansa said that they were very lucky to have a man with his qualifications on board at the time," Kevin Doyle of the Evening Herald told the paper.

Earlier on HuffPost: