Optogenetics is a powerful technique to control cellular activity by light. The light-gated Channelrhodopsin has been widely used to study and manipulate neuronal activity in vivo, whereas optogenetic control of second messengers in vivo has not been examined in depth. In this study, we present a transgenic mouse model expressing a photoactivated adenylyl cyclase (bPAC) in sperm. In transgenic sperm, bPAC mimics the action of the endogenous soluble adenylyl cyclase (SACY) that is required for motility and fertilization: light-stimulation rapidly elevates cAMP, accelerates the flagellar beat, and, thereby, changes swimming behavior of sperm. Furthermore, bPAC replaces endogenous adenylyl cyclase activity. In mutant sperm lacking the bicarbonate-stimulated SACY activity, bPAC restored motility after light-stimulation and, thereby, enabled sperm to fertilize oocytes in vitro. We show that optogenetic control of cAMP in vivo allows to non-invasively study cAMP signaling, to control behaviors of single cells, and to restore a fundamental biological process such as fertilization.