An optimal control algorithm for mitigating the effects of T1 and T2 relaxation during the application of long pulses is derived. The methodology is applied to obtain broadband excitation that is not only tolerant to RF inhomogeneity typical of high resolution probes, but is relatively insensitive to relaxation effects for T1 and T2 equal to the pulse length. The utility of designing pulses to produce specific phase in the final magnetization is also presented. The results regarding relaxation and optimized phase are quite general, with many potential applications beyond the specific examples presented here