Fluorescent proteins have been widely used as genetically encodable fusion tags for biological imaging. Recently, a new class of fluorescent proteins was discovered that can be reversibly light-switched between a fluorescent and a non-fluorescent state. Such proteins can not only provide nanoscale resolution in far-field fluorescence optical microscopy much below the diffraction limit, but also hold promise for other nanotechnological applications, such as optical data storage. To systematically exploit the potential of such photoswitchable proteins and to enable rational improvements to their properties requires a detailed understanding of the molecular switching mechanism, which is currently unknown. Here, we have studied the photoswitching mechanism of the reversibly switchable fluoroprotein asFP595 at the atomic level by multiconfigurational ab initio (CASSCF) calculations and QM/MM excited state molecular dynamics simulations with explicit surface hopping. Our simulations explain measured quantum yields and excited state lifetimes, and also predict the structures of the hitherto unknown intermediates and of the irreversibly fluorescent state. Further, we find that the proton distribution in the active site of the asFP595 controls the photochemical conversion pathways of the chromophore in the protein matrix. Accordingly, changes in the protonation state of the chromophore and some proximal amino acids lead to different photochemical states, which all turn out to be essential for the photoswitching mechanism. These photochemical states are (i) a neutral chromophore, which can trans-cis photoisomerize, (ii) an anionic chromophore, which rapidly undergoes radiationless decay after excitation, and (iii) a putative fluorescent zwitterionic chromophore. The overall stability of the different protonation states is controlled by the isomeric state of the chromophore. We finally propose that radiation-induced decarboxylation of the glutamic acid Glu215 blocks the proton transfer pathways that enable the deactivation of the zwitterionic chromophore and thus leads to irreversible fluorescence. We have identified the tight coupling of trans-cis isomerization and proton transfers in photoswitchable proteins to be essential for their function and propose a detailed underlying mechanism, which provides a comprehensive picture that explains the available experimental data. The structural similarity between asFP595 and other fluoroproteins of interest for imaging suggests that this coupling is a quite general mechanism for photoswitchable proteins. These insights can guide the rational design and optimization of photoswitchable proteins.