We present a new mechanism for the ejection of a common envelope in a massive binary, where the energy source is nuclear energy rather than orbital energy. This can occur during the slow merger of a massive primary with a secondary of 1-3 Msun when the primary has already completed helium core burning. We show that, in the final merging phase, hydrogen-rich material from the secondary can be injected into the helium-burning shell of the primary. This leads to a nuclear runaway and the explosive ejection of both the hydrogen and the helium layer, producing a close binary containing a CO star and a low-mass companion. We argue that this presents a viable scenario to produce short-period black-hole binaries and long-duration gamma-ray bursts (LGRBs). We estimate a LGRB rate of about 1.e-6 per year at solar metallicity, which implies that this may account for a significant fraction of all LGRBs, and that this rate should be higher at lower metallicity.