In a chilling reminder of how a simple human error can override the highest of high technology, an investigation has shown that All Nippon Airways Co. narrowly escaped a catastrophe earlier this month when its plane almost flipped over after a co-pilot hit the wrong button while trying to open the cockpit door for the plane's captain, returning from the restroom.

The revelation came at an awkward time for the Japanese carrier, just hours after the first of the new-generation Boeing Co. 787 Dreamliner jets on which it has built...