Calcium (Ca2+) signals that are precisely modulated in space and time mediate a myriad of cellular processes, including contraction, excitation, growth, differentiation and apoptosis(1). However, study of Ca2+ responses has been hampered by technological limitations of existing Ca2+-modulating tools. Here we present OptoSTIM1, an optogenetic tool for manipulating intracellular Ca2+ levels through activation of Ca2+-selective endogenous Ca2+ release-activated Ca2+ (CRAC) channels. Using OptoSTIM1, which combines a plant photoreceptor(2,3) and the CRAC channel regulator STIM1 (ref. 4), we quantitatively and qualitatively controlled intracellular Ca2+ levels in various biological systems, including zebrafish embryos and human embryonic stem cells. We demonstrate that activating OptoSTIM1 in the CA1 hippocampal region of mice selectively reinforced contextual memory formation. The broad utility of OptoSTIM1 will expand our mechanistic understanding of numerous Ca2+-associated processes and facilitate screening for drug candidates that antagonize Ca2+ signals.