A major challenge that limits the applications of nanostructured electrocatalysts is precise surface structure regulation. The critical performance-impeding factors for the important electrochemical ozone production (EOP) lie in the leaching-induced poor stability as well as the competing oxygen evolution and ozone production reactions over the most promising platinum-based electrocatalysts. Although composition diversification by alloying appears to be a prevailing strategy to optimize platinum-based electrocatalysts, a practical restriction turns out to be the inevitable surface segregation and termination of platinum-enriched structures due to their lower surface energies. In this work, we introduce the nanoconfinement of intermetallic platinum–nickel nanostructures encapsulated by boron carbide, which effectively frustrates the surface segregation of alloy nanostructures and well maintains the pristine termination of the alloy. Precise atomic-level structural elucidation and model construction of the encapsulated alloy nanostructures are achieved by quantitative electron microscopy. The composite nanoalloy with a unique surface termination evokes synergetic catalytic effects that promote the charge transfer between the surface and adsorbed oxygen intermediates, which entails outstanding EOP performance with a high Faraday efficiency of 14.8% in neutral media and long-term stability of up to 120 h as a qualified electrocatalyst for the EOP electrolyzer devices. More importantly, the current work paves a new route to overwhelm the thermodynamically limited surface structures of bare nanoalloy catalysts through diverse nanoconfinement strategies.