Quantum mechanical calculations are frequently used in computational surface science for predicting catalytic activities, for elucidating chemical processes, and for interpreting spectroscopic experiments. In recent years, several methods have been developed to extend the application of electronic-structure methods to surface electrochemistry. Nevertheless, computational approaches to treat electrochemical systems (e.g., fuel cells and batteries) as a function of the applied voltage had been lacking. We have developed an atom-continuum model for the first-principles simulation of catalytic systems under electrochemical conditions. We have implemented and validated an efficient algorithm to solve the underlying nonlinear generalized Poisson equations. The approach is applied to the first-principles description of the voltage dependence of vibrational frequencies (the vibrational Stark effect) for CO on platinum electrodes, finding excellent agreement with electrochemical spectroscopic experiments and resolving previous controversies.