He was caught with his pants down.

A pilot who accidentally locked himself in the bathroom of his LaGuardia-bound plane caused a terror scare last night when a helpful passenger with an accent tried to come to his rescue by banging on the cockpit door.

The embarrassing comedy of errors began when the captain of a Chatauqua Airlines flight from Asheville, N.C., decided to take a bathroom break before landing.

But when he tried to get out of the men’s room, the door jammed, trapping him in the tight quarters.

Desperate to get out and land the plane — which was in a holding pattern above the airport — he pounded his fists on the door to attract attention.

A well-intentioned passenger sitting in the front row heard his thumping and hurried over to help.

Relieved, the pilot told the passenger to go to the cockpit and alert the crew to his plight.

But crew members didn’t react well to the unexpected visit from a stranger trying to breach the highly secure area of the plane.

Click here to read more of this story from the New York Post.