In Chapter 18 of Genesis two angels and God appeared at Abraham's tent. Abraham saw them and thought they were three men, so he rushed to extend his hospitality to the guests. Hospitality was of very high importance to Abraham's culture, and he did everything right. He set Sarah to work kneading flour, prepared a calf, and provided curds and milk. After this, the angels and the LORD revealed themselves to Abraham and told him that Sarah would bear a child. Sarah, who was eavesdropping, laughed at this, and the LORD scolded her. Sarah, afraid, denied laughing.
After this, the LORD forewarned Abraham that he was going to destroy the city of Sodom. This was a turning point in the narrative - God had never before used Abraham as a confidant, and Abraham jumped right on top of his new level of relationship by questioning "Suppose there are fifty righteous within the city. Will you then sweep away the place and not spare it for the fifty righteous who are in it?" (Genesis 18:24 ESV). When the LORD said that he would not sweep away the city for the sake of the fifty, Abraham questioned about forty-five, forty, thirty, twenty, and ten. Each time the LORD answered that he would save the city for the sake of those righteous people.
Then, the two angels went down to Sodom. Lot saw them, and thinking they were men, invited them to his home, and provided a feast. But the evil men of Sodom surrounded Lot's house and demanded the guests be sent out so the men could sodomize them. Lot stepped out into danger himself and refused to send out the guests, instead offering his virgin daughters as an exchange. When the evil men of the city threatened to worse-than-sodomize Lot, the angels intervened and struck blind the men at the gate. They told Lot to take his entire family, including his daughters' grooms, and leave the city for it was about to be destroyed. But Lot's sons-in-law thought he was joking and didn't heed the warning. The angels insisted, and finally Lot left the city with only his daughters and wife. They were told not to look back, and because Lot's wife looked back, she was turned to a pillar of salt.
Lot was living in a cave alone with his daughters, who were concerned that there were no longer men to marry. They worried that Lot's line would thus end. So they got Lot drunk and raped him while he was passed out.
This is an early example of the thriller/suspense genre. The reader hears that these cities will be destroyed, and wonders (along with Abraham) whether God will destroy the righteous with the evil. And how will God respond at being questioned so closely by Abraham? Did Abraham overstep his relationship with God? It seems not, because God answered Abraham patiently and kept his promise.
The suspense heightens throughout the story, with each incident showing how evil the men of Sodom were and how righteous Lot was. That is, assuming that when the story was written readers would interpret Lot's offer of his virgin daughters instead of his guests as the height of hospitality (and therefore worthy of God's smiles). Of course, to me, sending out innocent girls doesn't seem a good solution at all.
The action peaks when Lot's wife is turned to a pillar of salt because she looks back at the destruction of Sodom. This don't-look-back plot point is similar to the older story of Orpheus, who went on a quest into Hades to rescue his deceased (and dearly loved) wife Eurydice. He was told not to look back when leaving Hades, but couldn't resist looking back to see the face of Eurydice, who then disappeared back into Hades.
The end of the story is a bit puzzling. Why, after Lot had been so righteous throughout the story, was he rewarded by being raped by his daughters? Surely this incest was just as disgusting to the readers of the time as it would be to us?
The notes in The Literary Study Bible have a different interpretation of Lot's righteousness than I do. It points out that despite the New Testament commentary on Lot as a righteous man (2 Peter 2:6-8), Lot was closely tied to the evil city of Sodom. This close tie was shown by his reluctance to leave the city, even when the angels said that it would be destroyed. They had to drag him out of the city by his hand, in fact. The commentary ends by saying "it is easier to get the family out of Sodom than it is to get Sodom out of the family."