Keri (קרי) is a Hebrew term which literally means "happenstance", "frivolity" or "contrariness" and has come to mean "seminal emission". The term is generally used in Jewish law to refer specifically to the regulations and rituals concerning the emission of semen, whether by nocturnal emission, or by sexual activity. By extension, a man is said to be a ba'al keri (בעל קרי) ("one who has had a seminal emission") after he has ejaculated without yet completing the associated ritual cleansing requirements.
The biblical regulations of the Priestly Code specify that a man who had experienced an emission of semen would become ritually impure, until the evening came and the man had washed himself in water; () any clothes or bits of skin which the semen came into contact with would also become ritually impure, until they had been washed in water and the evening had come. () The code adds that if the emission of semen occurred during sexual intercourse with a woman, then the woman would also become ritually impure, until the evening had come and she had washed herself in water. ()
Non-traditional biblical scholars see these regulations as having originally derived from taboo against contact with semen, because it was considered to house life itself, and was thus thought of as sacred.
The Talmud adds prohibitions designed to avoid keri in cases that don't involve sexual intercourse. It was forbidden for a man to investigate himself to determine whether an emission of semen had occurred, on the basis that the sensation of touch causes keri (an oblique reference to masturbation); the Talmud goes on to address the concern that preventing any contact with the penis would make urination more awkward for males, and makes suggestions in this regard.
The Talmud (Bava Kamma 82b) states that one who experienced an emission of semen is required by the Torah to immerse in water in order to be allowed to consume from a heave offering or sacrifice; while Ezra instituted that one should also do so in order to be allowed to recite words of Torah.
The Talmud relates that Ezra's decree forbidding a ba'al keri from studying Torah no longer applies nowadays. Some dispute exists amongst the Rishonim as to whether or not this applies to prayer as well. Rav Hai Gaon (brought in the commentary of Yonah Gerondi on Berakhot) and Chananel ben Chushiel (brought in Tosafot Hullin 122b) say that a ba'al keri, while he may study Torah, may not pray until he goes to a mikveh. Maimonides (Hilkhot Kriat Shma 4:8) says that the decree was cancelled entirely and a ba'al keri may even say Kriat Shma. Maimonides goes on to say, however, that the minhag in Shinaar and Spain is that before prayer a ba'al keri should wash himself entirely with water (Hilkhot Tefillah 4:6). The consensus is that it is praiseworthy for a ba'al keri to immerse himself in the mikveh before praying, Kriat Shma, saying Berakhot etc.