Light-triggered reversible modulation of physiological functions offers the promise of enabling on-demand spatiotemporally controlled therapeutic interventions. Optogenetics has been successfully implemented in the heart, but significant barriers to its use in the clinic remain, such as the need for genetic transfection. Herein, we present a method to modulate cardiac function with light through a photoswitchable compound and without genetic manipulation. The molecule, named PAI, was designed by introduction of a photoswitch into the molecular structure of an M2 mAChR agonist. In vitro assays revealed that PAI enables light-dependent activation of M2 mAChRs. To validate the method, we show that PAI photoisomers display different cardiac effects in a mammalian animal model, and demonstrate reversible, real-time photocontrol of cardiac function in translucent wildtype tadpoles. PAI can also effectively activate M2 receptors using two-photon excitation with near-infrared light, which overcomes the scattering and low penetration of short-wavelength illumination, and offers new opportunities for intravital imaging and control of cardiac function.