- "And so ascended the king's younger brother, Maegor the Cruel. His first act was to challenge the Faith Militant to kill him, if they believed his rule to be ungodly. To the order's eternal credit, they accepted. Ser Damon Morrigen proposed a 'Trial by Seven', Ser Damon and six of the Faith Militant against the king and his six champions. It was a contest in which the kingdom itself was at stake, and the accounts and tales are many. But at the end of it, Maegor alone lived, proving that the throne was rightfully his. "
- ―High Sparrow
The Trial by Seven of Maegor Targaryen was an event at the beginning of the Faith Militant uprising.
When the Faith Militant rose in revolt against House Targaryen, they overwhelmed the new capital city King's Landing, causing the weak King Aenys Targaryen to flee to Dragonstone - where he soon died from the stress.
Aenys's half-brother Maegor Targaryen then usurped the crown and returned to King's Landing, where he challenged the Faith Militant's champions to a trial of seven to prove his right to rule. Bound by honor and their beliefs, the Faith Militant agreed - such a holy trial would allow the gods to decide and give favor to the rightful party (which they probably hoped also meant that they could kill Maegor without risking further loss of life to the city and the realm, bringing Targaryen rule to a swift and relatively bloodless end).
The fate of the realm hung in the balance during their confrontation. Many tales are told about it, but after a long and epic fight, at the end Maegor alone remained alive.
In the books
When Maegor flew back to King's Landing from Dragonstone, he actually didn't fly immediately to the Red Keep: it remained occupied by the Faith Militant after Aenys fled the city. Afterwards, the Faith Militant managed to hold the heights at both Rhaenys's Hill (with the Sept of Remembrance on top) and Aegon's Hill (with the half-built Red Keep on top). Instead, when Maegor came to the city he flew directly to Visenya's Hill, which apparently wasn't as firmly held by the Faith Militant (the Great Sept of Baelor wouldn't be built there until over a century and a half later). Maegor then raised the red dragon banner of House Targaryen on Visenya's Hill to rally men to him, and thousands came.
Ser Raymont Baratheon was instrumental in saving Aenys's life during the earlier assault on the Red Keep, but it is unclear if he died saving Aenys - meaning it is unclear if he was one of the six Kingsguard present during the trial of seven.
Maegor specifically fought the Warrior's Sons - the upper order of the Faith Militant that is recruited from former knights and younger noble sons. The TV show omitted the detail that there are two internal orders to the Faith Militant. Damon Morrigen was himself the captain of the entire King's Landing chapter of the Warrior's Sons (which according to semi-canon sourced numbered about 700 men).
Maegor was actually fell into a coma from the wounds he took in his trial of seven against the Faith Militant's champions - though of the fourteen men who walked onto the field he was the only one left alive.
He remained unconscious for about a month in the Red Keep, until his mother the Dowager Queen Visenya Targaryen sent for Maegor's polygamous third wife, Tyanna of Pentos, from across the Narrow Sea. Rumored to be a sorceress and alchemist skilled with poisons but also medicine, Tyanna managed to treat Maegor, who woke with the sun the next day - and proceeded to burn the Sept of Remembrance with Balerion.