Abnormalities in the specialized cardiac conduction system may result in slow heart rate or mechanical dyssynchrony. Here we apply optogenetics, widely used to modulate neuronal excitability, for cardiac pacing and resynchronization. We used adeno-associated virus (AAV) 9 to express the Channelrhodopsin-2 (ChR2) transgene at one or more ventricular sites in rats. This allowed optogenetic pacing of the hearts at different beating frequencies with blue-light illumination both in vivo and in isolated perfused hearts. Optical mapping confirmed that the source of the new pacemaker activity was the site of ChR2 transgene delivery. Notably, diffuse illumination of hearts where the ChR2 transgene was delivered to several ventricular sites resulted in electrical synchronization and significant shortening of ventricular activation times. These findings highlight the unique potential of optogenetics for cardiac pacing and resynchronization therapies.