In this paper, we introduce optimal control algorithm for the design of pulse sequences in NMR spectroscopy. This methodology is used for designing pulse sequences that maximize the coherence transfer between coupled spins in a given specified time, minimize the relaxation effects in a given coherence transfer step or minimize the time required to produce a given unitary propagator, as desired. The application of these pulse engineering methods to design pulse sequences that are robust to experimentally important parameter variations, such as chemical shift dispersion or radiofrequency (rf) variations due to imperfections such as rf inhomogeneity is also explained.