The device and method for phase-locking brain stimulation to electroencephalographic rhythms improves the accuracy, specificity, and effectiveness of non-invasive brain stimulation devices by timing pulses of brain stimulation to occur in synchrony with naturally occurring brain rhythms measured at the scalp of a patient in order to treat an assortment of neurological and psychiatric conditions. The device and method provided herein improve non-invasive brain stimulation techniques by time-locking the onset of brain stimulation to the phase of naturally-occurring rhythmic oscillations of brain activity that can be recorded with electroencephalography (EEG). The device and method perform real-time signal analysis of a specified EEG rhythm, extract frequency-domain phase information to estimate the next occurrence of a desired EEG rhythm phase, and trigger a brain stimulation pulse so as to align precisely with this predicted EEG phase.