Margaery was married to Robert's brother, Renly, who was also trying to capture the throne of Westeros, but she was left a widow after Renly was killed. Her family, the Tyrells, are one of the most powerful in the kingdom, and she and her brother come to King's Landing where her brother presents her as a possible fiancé to King Joffrey. Joffrey was engaged to Ned Stark's daughter, Sansa, whom he regularly physically and emotionally abused, but he and his advisers recognize the value of allying themselves with Margaery's family rather than marrying a member of the Stark family, with whom they are at war. So Joffrey becomes engaged to Margaery, leaving Sansa's status at court in doubt.

Margaery Tyrell (l.) and King Joffrey (r.)
Helen Sloan/HBO