It's used to emphasize that something is true or real, and not figurative or metaphorical.
Example:
* Correct: "I literally ran a marathon yesterday." (You actually ran a marathon.)
* Incorrect: "I was literally dying of laughter." (You were not actually dying.)
Note: "Literally" is often misused. People use it as a synonym for "very" or "extremely" which is incorrect.