Pulsing transcranial magnetic stimulation (TMS) in synchrony with endogenous brain rhythms may have greater effects on both local and distributed neural activity than non-synchronized stimulation with this change being of possible clinical significance. To better understand the mechanisms that underlie treatment efficacy, we developed an instrument that can trigger synchronized stimulation at a target phase via real-time processing of the electroencephalogram (EEG) while concurrently recording hemodynamic response at high spatial resolution via functional magnetic resonance imaging (fMRI). EEG was recorded and processed at a sampling rate of 488Hz. For phase tracking and prediction, the prefrontal alpha oscillation was recovered using a finite impulse response filter (order 50) on the spatial average of four left frontal EEG electrodes (FP1, AF3, F3 and F7). Subsequently, a sine model was fit onto a time window that was extracted from 307 to 102ms before the most recently acquired EEG sample. Fitting was accomplished by minimizing root mean squared error (RMSE) via nonlinear optimization for the free amplitude, frequency and phase parameters. RMSE was then computed for phase and amplitude between the model prediction and the signal in a test window from 102 to 0ms prior to the same reference point as before. If the RMSE values for the test window were below fixed conservative thresholds, the time point for the next target-phase in the alpha rhythm was predicted up to 123ms in the future and a pulse event was registered once the predicted time had passed. Triggering was always followed by a refractory period of 5s, in which new EEG data was preprocessed but sine fitting and triggering remained disabled. To establish a performance baseline, the system was first tested outside the scanner with eleven healthy subjects, where the system was able to mark a phase target of 90 degrees at a mean phase error of 0.8 degrees (standard deviation: 45.4). During subsequent tests on three healthy subjects where fMRI data was recorded concurrently, all EEG data processing was preceded by real-time gradient artifact removal. Phase prediction accuracy was found to be comparable to recordings outside the scanner. The performance achieved by this instrument will allow us to probe causal hypotheses relating the phase of ongoing endogenous oscillations to behavior and the TMS induced BOLD response.