The accuracy and repeatability of atomic force microscopy (AFM) imaging significantly depend on the accuracy of the piezoactuator. However, nonlinear properties of piezoactuators can distort the image, necessitating sensor-based closed-loop actuators to achieve high accuracy AFM imaging. The advent of high-speed AFM has made the requirements on the position sensors in such a system even more stringent, requiring higher bandwidths and lower sensor mass than traditional sensors can provide. In this paper, we demonstrate a way for high-speed, high-precision closed-loop AFM nanopositioning using a novel, miniaturized micro-electromechanical system position sensor in conjunction with a simple PID controller. The sensor was developed to respond to the need for small, lightweight, high-bandwidth, long-range and subnm-resolution position measurements in high-speed AFM applications. We demonstrate the use of this sensor for closed-loop operation of conventional as well as high-speed AFM operation to provide distortion-free images. The presented implementation of this closed-loop approach allows for positioning precision down to 2.1 angstrom, reduces the integral nonlinearity to below 0.2%, and allows for accurate closed loop imaging at line rates up to 300 Hz.