Objective. Deep brain stimulation (DBS) of the internal segment of the globus pallidus (GPi) in patients with Parkinson’s disease and dystonia improves motor symptoms and quality of life. Traditionally, pallidal borders have been demarcated by electrophysiological microelectrode recordings (MERs) during DBS surgery. However, detection of pallidal borders can be challenging due to the variability of the firing characteristics of neurons encountered along the trajectory. MER can also be time-consuming and therefore costly. Here we show the feasibility of real-time machine learning classification of striato-pallidal borders to assist neurosurgeons during DBS surgery. Approach. An electrophysiological dataset from 116 trajectories of 42 patients consisting of 11,774 MER segments of background spiking activity in five classes of disease was used to train the classification algorithm. The five classes included awake Parkinson’s disease patients, as well as awake and lightly anesthetized genetic and non-genetic dystonia patients. A machine learning algorithm was designed to provide prediction of the striato-pallidal borders, based on hidden Markov models and the L1-distance measure in normalized root mean square (NRMS) and power spectra of the MER. We tested its performance prospectively against the judgment of 3 electrophysiologists in the operating rooms of three hospitals using newly collected data. Main results. The awake and the light anesthesia dystonia classes could be merged. Using MER NRMS and spectra, the machine learning algorithm was on par with the performance of the three electrophysiologists across the striatum-GPe, GPe-GPi, and GPi-exit transitions for all disease classes. Significance. machine learning algorithms enable real-time GPi navigation systems to potentially shorten the duration of electrophysiological mapping of pallidal borders, while ensuring correct pallidal border detection.