Riot of King's Landing

"They threw a cowpie at you, so you decide to kill them all?! They're starving, you fool! All because of a war you started!"

- Tyrion Lannister to King Joffrey Baratheon

The Riot of King's Landing was an event during the War of the Five Kings. After seeing off Princess Myrcella Baratheon at the docks on a ship bound for Dorne, the royal procession including King Joffrey is subjected to the jeers of the starving crowds of the capital city, culminating in Joffrey foolishly ordering his outnumbered personal guard to execute the entire crowd, sparking off a city-wide riot.

Background
After the outbreak of the War of the Five Kings, the problems in King's Landing multiplied, particularly the worsening foot shortages. In normal times, food is mostly brought in to the capital city from the Reach and the Riverlands, because the Crownlands alone cannot feed its large population. However, the Riverlands could not send food, because House Tully had sided with Robb Stark's rebellion, and the southern portions of the Riverlands that Lannister armies nominally controlled were reduced to a burned-out, ravaged warzone. Meanwhile, House Tyrell of the Reach sided with King Renly Baratheon, cutting off food shipments to the capital along the Roseroad. Even though Renly recently died not long before the riot, House Tyrell was still wavering in which faction to subsequently realign itself with, and had not resumed food shipments.

Added to this, there was a large influx of refugees from the Riverlands into the city since the war began, seeking the protection of the city walls. This drastically exacerbates the food shortages. Lord Commander Janos Slynt of the City Watch had desperately tried to convince Queen Cersei that the dire situation was spiraling out of control, as did her brother Tyrion, but she waved aside such concerns.

The Riot
As the royal procession worked their way back to the Red Keep, crowds of peasants gathered around them, and some began sarcastically shouting empty praises at Joffrey. Soon they began begging for bread because they are starving due to the disruptions in trade due to the war. After being subjected to the japes and jests of the crowd, including shouts of "bastard!", "monster of incest!", and "Stannis!", someone threw a cowpie at King Joffrey's head.

Enraged at the excrement thrown in his face, Joffrey demanded that his guards seize whoever threw it. With mounting frustration, Joffrey became livid, and simply shouted out "Just kill them! Kill them all!" Unfortunately for Joffrey, normally used absolute power in ordering the torment of Sansa Stark or defenseless peasants dragged into the throne room, his word actually wasn't law. Utterly failing to realize that he wasn't in the safety of the Red Keep with its large garrison, Joffrey's few dozen guards were quickly overwhelmed by hundreds of panicking and angry commoners and refugees. The High Septon was dragged down screaming by the crowd and torn limb from limb.

The Kingsguard carved a path through the mob with their swords, barely managing to rush Joffrey, Cersei, and Tyrion to the security of the Red Keep. Joffrey was left fuming, but Tyrion blamed Joffrey for inciting the starving crowd. When Tyrion realizes that Sansa Stark has been separated from the group and is still outside a petulant Joffrey refused to order his Kingsguard to go after her, even though she was a vital hostage. Sansa was nearly raped before Sandor Clegane saved her. When Tyrion tries to thank Sandor for saving Sansa and averting a political disaster, Sandor says, "I didn't do it for you."

Aftermath
Much of the city remained in chaos for some time, with random violence and looting spreading across the capital. The pent up frustrations with Lannister rule and the starvation conditions in the city which Queen Cersei had flippantly ignored for months now came back to haunt Joffrey's court.

In the books
In the books, the Riot of King's Landing is considerably more violent. The party of nobles and their guards are on horseback not on foot. The riot begins after a woman walks out before King Joffrey's horse, halting the procession. She holds up her dead baby, which died from malnutrition due to the war he started. Tyrion sees Sansa say something to Joffrey, and Joffrey callously tosses one silver coin at the woman. It bounces off the dead baby to roll into the crowd, where people fight over it. The woman begins screaming insults at Joffrey and Cersei (accurately shouting that they are a "bastard" and a "brother-fucker", respectively). The crowd takes this up as well and then someone throws manure at Joffrey and he demands the culprit to be executed (the book does not specify that it is cow manure, but given the food situation it is unlikely that a lot of cows are around).

In the ensuing violence, Ser Preston Greenfield of the Kingsguard and Ser Aron Santagar, the Red Keep's master-at-arms are killed. Nine Gold Cloaks are also killed and 40 are wounded. Lollys Stokeworth - daughter of Lady Tanda Stokesworth - is raped by dozens of men, and is found wandering naked by the Gold Cloaks. Tyrek Lannister, one of Robert's former squires, simply disappeared in the riot, his body never found. Nobody bothers to count all the dead rioters. The High Septon is also torn limb from limb in the book (this is not an invention of the TV series), leading Tyrion to quip that "starving men take a dim view of priests too fat to walk".

The book does not indicate if there was an attempt to rape Sansa: the Hound does rescue her and bring her back within the castle after all of the knights inside refuse to risk going out again, but this chapter is narrated from Tyrion's POV so the details of her rescue are not shown.

After the riots, Tyrion begins a curfew from dusk to dawn, with the penalty that anyone found on the streets will be killed. This measure is horribly unpopular, but curtails the nightly murder-robberies that have been taking place. The growing danger in the city is what prompts Tyrion to bring Shae into the Red Keep for safety. With Varys' help he gets her a position as handmaiden to Lollys Stokesworth, who becomes pregnant after being raped. Tyrion and Varys both try very hard to find Tyrek Lannister who is Tyrion's cousin and whose father Tygett was his favorite uncle, but so far his fate is unknown. His body was never found (Jaime has suspicions that Varys might have something to do with Tyrek's disappearance).