First-principles calculations combining density-functional theory and continuum solvation models enable realistic theoretical modeling and design of electrochemical systems. When a reaction proceeds in such systems, the number of electrons in the portion of the system treated quantum mechanically changes continuously, with a balancing charge appearing in the continuum electrolyte. A grand-canonical ensemble of electrons at a chemical potential set by the electrode potential is therefore the ideal description of such systems that directly mimics the experimental condition. We present two distinct algorithms, a self-consistent field method (GC-SCF) and a direct variational free energy minimization method using auxiliary Hamiltonians (GC-AuxH), to solve the Kohn-Sham equations of electronic density-functional theory directly in the grand canonical ensemble at fixed potential. Both methods substantially improve performance compared to a sequence of conventional fixed-number calculations targeting the desired potential, with the GC-AuxH method additionally exhibiting reliable and smooth exponential convergence of the grand free energy. Finally, we apply grand-canonical DFT to the under-potential deposition of copper on platinum from chloride-containing electrolytes and show that chloride desorption, not partial copper monolayer formation, is responsible for the second voltammetric peak.Density-functional theory (DFT) enables theoretical elucidation of reaction mechanisms at complex catalyst surfaces, making it now possible to design efficient heterogeneous catalysts for various industrial applications from first principles, for example for high-temperature gas-phase transformation of hydrocarbons to a variety of valuable chemical products. 1,2 The extension of this predictive power to electrocatalysis would be highly valuable for an even broader class of technological problems, including a cornerstone of future technology for renewable energy: converting solar energy to chemical fuels by electrochemical water splitting and carbon dioxide reduction. 3 Accurately describing electrochemical phenomena, however, presents two additional challenges.First, the electrolyte, typically consisting of ions in a liquid solvent, strongly affects the energetics of structures and reactions at the interface. Treating liquids directly in DFT requires expensive molecular dynamics to sample the thermodynamic phase space of atomic configurations. Historically, a number of continuum solvation models that empirically capture liquid effects have enabled theoretical design of liquid-phase catalysts. 4,5 More recently, empirical solvation models suitable for solid-liquid interfaces, 6-8 joint density-functional theory (JDFT) for efficiently treating liquids with atomic-scale structure, 9 and minimally-empirical solvation models derived from JDFT, 10,11 have made great strides towards a) Electronic mail: sundar@rpi.edu b) Electronic mail: wag@wag.caltech.edu c) Electronic mail: taa2@cornell.edu reliable yet efficient treatment of electrochemica...