Because of suboptimal therapeutic strategies, restoration of sinus rhythm in symptomatic atrial fibrillation (AF) often requires in-hospital delivery of high-voltage shocks, thereby precluding ambulatory AF termination. Continuous, rapid restoration of sinus rhythm is desired given the recurring and progressive nature of AF. Here, we present an automated hybrid bioelectronic system for shock-free termination of AF that enables the heart to act as an electric current generator for autogenous restoration of sinus rhythm. We show that local, right atrial delivery of adenoassociated virus vectors encoding a light-gated depolarizing ion channel results in efficient and spatially confined transgene expression. Activation of an implanted intrathoracic light-emitting diode device allows for termination of AF by illuminating part of the atria. Combining this newly obtained antiarrhythmic effector function of the heart with the arrhythmia detector function of a machine-based cardiac rhythm monitor in the closed chest of adult rats allowed automated and rapid arrhythmia detection and termination in a safe, effective, repetitive, yet shock-free manner. These findings hold translational potential for the development of shock-free antiarrhythmic device therapy for ambulatory treatment of AF.