Crying is the shedding of tears (or welling of tears in the eyes) in response to an emotional state - as distinct from non-emotional 'lacrimation' which is the medical term for non-emotional shedding of tears (e.g. in response to peeling onions).
Despite intense efforts from physicians, psychologists and philosophers, the origins of crying in humans, its function, and any possible evolutionary advantages, are not yet agreed upon.
“The question of the function or origin of emotional tears remains open. Theories range from the simple, such as response to inflicted pain, to the more complex, including nonverbal communication in order to elicit altruistic behavior from others. Some have also claimed that crying can serve several biochemical purposes, such as relieving stress. Crying is believed to be an outlet or a result of a burst of intense emotional sensations, such as agony, surprise or joy. This theory is more plausible as it explains why people cry during cheerful events, as well as very painful events.”
Note: Anecdotal evidence suggests that crying is not restricted to humans. There are reports of crying in elephants, chimpanzees, deer, giraffes, bears, seals, etc.