Magnetic resonance imaging (MRI) has had a profound impact on biology and medicine. Key to its success has been the unique ability to combine imaging with nuclear magnetic resonance spectroscopy—a capability that has led to a host of powerful modalities for imaging spins. Although it remains a significant challenge, there is considerable interest to extend these powerful spectroscopic and imaging capabilities to the nanometer scale. In this talk, I will discuss a new platform for force-detected magnetic resonance detection that allows us to bring many aspects of NMR spectroscopy to the nanometer scale. In particular, I will focus on the development of optimal control theory (OCT) pulses that incorporate average Hamiltonian theory and realize high fidelity unitary operations. I will present recent results demonstrating the use of OCT-based line narrowing pulse sequences that suppress the dipolar evolution and increase the coherence time of proton spins in polystyrene at 4 K by a factor of 500, from 11 μs to 6 ms. This advance has allowed us to image proton spins in one dimension spatial resolution below 2 nm. More generally, through the use of OCT pulses, we now have the ability to perform high-resolution NMR spectroscopy on nanometer scale nuclear spin ensembles.