About a 100-fold improvement of the second-harmonic generation in a quantum-cascade laser with integrated optical nonlinearity was obtained by including phase-matching considerations in the design of the deep-etched ridge waveguide. The waveguide layer structure was optimized to minimize the phase mismatch of the zero-order mode of the fundamental light with the second-order transverse mode of the second-harmonic light. Exact phase matching is made possible by the faster decrease of the modal refractive index of the fundamental light with decreasing ridge width relative to the refractive index of the second-harmonic light. Up to 240 μW of the second-harmonic power and a nonlinear power conversion efficiency of up to 36 mW/W2 were achieved.