When Donald Trump flew to Iraq on Christmas Day for a top secret visit, the US government took every precaution to avoid the news leaking out. Journalists were sworn to secrecy, while Air Force One flew with its lights off and was accompanied by fighter jets for part of the journey.

The US military had not reckoned with a planespotter from the suburbs of Sheffield, who took a photograph of the president’s plane in the sky over Yorkshire and inadvertently helped to break news of the flight to the Middle East while Trump was still in the air.

Alan Meloy, a semi-retired former NHS IT manager with an interest in aircraft and railways, was standing outside his house on Boxing Day when he spotted a jumbo jet.

“It’s one of those weird moments where you’re right place and right time,” he said. “Boxing Day dawns clear and bright, the next thing there’s an interesting airplane.”

Meloy took out a camera with a long lens he uses for birdwatching and took a picture, planning to add it to the thousands of aircraft photos he has uploaded to the internet over the years. Then he noticed this one had a distinctive livery.

“I could see stars and bars and the great big flag on the tail,” he said, identifying it as a VC-25 – one of two pastel-blue modified Boeing 747s used to ferry the US president around the world. “I have not seen Air Force One over South Yorkshire since 2005. It’s not something you see regularly.”

After uploading the picture to the photo sharing site Flickr, the image was picked up by other aircraft enthusiasts who combined it with publicly available aircraft tracking data relating to a mysterious military flight. They concluded Trump was on a secret trip to the Middle East, hours before he touched down for his first visit to a war zone.

As a result, the White House was forced to reveal details of the trip ahead of time, throwing media management and security plans into chaos.

Asked if he had security concerns about the trip, Trump, who was accompanied by his wife, Melania, told reporters in Iraq: “I had concerns about the institution of the presidency. Not for myself personally. I had concerns for the first lady, I will tell you.”

The president also told journalists that he had never seen anything like the security measures taken to ensure the secrecy of his flight: “If you would have seen what we had to go through in the darkened plane with all windows closed with no light anywhere. Pitch black. I’ve been on many airplanes … I’ve never seen anything like that.”

Meloy, who has found himself at the centre of a media circus, said there were lessons to be learned: “If you want to do covert work use a covert plane.”

When asked whether it was worth Trump keeping the window blinds down during the trip, Meloy delivered a straightforward verdict: “Well that made a big difference. And he’s not seen Yorkshire.”