Ecclesiarchy
"Hence Theocracy is the worst of all governments. If we must have a tyrant, a robber baron is far better than an inquisitor. The baron's cruelty may sometimes sleep, his cupidity at some point may be sated; and since he dimly knows he is doing wrong he may possibly repent. But the inquisitor who mistakes his own cruelty and lust of power and fear for the voice of Heaven will torment us infinitely more because he torments us with the approval of his own conscience and his better impulses appear to him as temptations."
-C.S. Lewis
The Adeptus Ministorum, or Ecclesiarchy, is the state church of the Imperium of Man and works with the Inquisition, making it the group which defines heresy.

When the Emperor of Mankind began setting up the Imperium, he began instituting the Imperial Truth, which basically said "there are no gods and we're doing science and reason now". Yet even during the Great Crusade people began worshiping the Emperor as a "God-Emperor", including his own son Lorgar, who wrote the Lectitio Divinatus. Which, ironically, proved effective at causing pain to daemons when lines from it were spoken to them. Suitably embarrassed, the Emperor politely informed Lorgar to stop worshiping him the bullshit. By having the Ultramarines destroy a city the Word Bearers set up and then forcing Lorgar to bow down to Himself, Malcador the Sigillite, and Roboute Guilliman in front of his legion. Somewhat unsurprisingly, especially when he forced Lorgar to bow to one of those smurfs In an unfathomable and completely-impossible-to-predict act of Heresy, this would lead to Lorgar worshiping the Chaos Gods and starting the Horus Heresy. The Emperor was not particularly empathetic The Emprah, beloved by All, was saddened.
Age of Apostasy
After the Emprah was hooked up to the Golden Throne, a "Cult of the Savior Emperor" (more often referred to as the "Imperial Cult", since every Imperial's a member) was set up and eventually became the state religion as the Adeptus Ministorum, declaring the Emperor's very own Imperial Truth as Heresy. Well, more like claiming that the Emperor was trying to protect them through encouraging their ignorance of daemons. After all, declaring the Emperor's laws to be heresy would not go over well with the Astartes and Custodes.
The Ecclesiarch, the head of the Ministorum, eventually got on the High Lords of Terra, eventually supplanting the Master of the Administratum (the guy who actually runs the government) as head of the Council, starting the Age of Apostasy. After that, the Ecclesiarchy started becoming what every powerful group in the Imperium does: more interested in its own power than the people they're supposed to be ministering to, and public funds and taxes ended up funneling their way into the church, and religious officials were making decisions on national policy and the like, since the Ecclesiarchy figured that the church and the state should be pretty much the same thing and
Things took a major turn for the worse when Goge Vandire, the Master of the Administratum, became Ecclesiarch at the same time, making himself the single most powerful person in the Imperium and started the Reign of Blood. Even by 40k standards this guy was nutters: He convinced an all-female sect called the "Daughters of the Emperor" rename themselves the "Brides of the Emperor" and become his bodyguards. He instituted big brother policies of having Servo-skulls on every street corner listening for sedition, and engaged in mass executions for the lulz.
A "rogue" preacher named Sebastian Thor and his sect (the Confederation of Light), supported by a couple Space Marine Chapters and the Adeptus Mechanicus, went "fuck this" and invaded Terra to remove Vandire from the throne (so to speak). To the surprise of all present (except the Brides/Daughters), the defenders not only held off the invaders, but actually managed to give them a real beating. Before things got out of hand, the Adeptus Custodes took the leader of the Daughters to the Golden Throne to have a chat with the Emperor. She got insanely pissed off by something that happened there and cut off Vandire's head.
How the daughters held off a vastly superior force before they had vehicles, powered armor, acts of faith, Living Saints, and bolters is anyone's guess. Probably just thoughtless writing. I doubt the Custodes would just let them use the Palace's defense points. Hell, they'd probably open the gates for the "invaders", personally.
Thorian Reformation
Afterwards, Thor started the Thorian Reformation, in which the Temple of the Saviour Emperor was supplanted by Thor's Confederation of Light. The Ecclesiarchy was stripped of all military power, but, fortunately for them, they were specifically banned from keeping "men under arms", and so they reformed the Daughters into the Battle Sisters of the Adepta Sororitas. The Inquisition also set up the Ordo Hereticus to make sure no one deviated from these new rules. The reformed Ecclesiarchy is only slightly less corrupt and divorced from reality as it was before, but now they feel guilty and beat themselves (and, unfortunately, everyone they minister to, which means every subjects of the Imperium) up about it! Occasionally, they even try (and fail) to fix it!
Temple Tendency
Sadly, some people are still particularly abusive, and these people are accused of having a "temple tendency." Additionally, there's an actual heretic group called the Temple Tendency. They believe the Confederation of Light are the real traitors and (secretly) preach their creed in the hopes of turning back the clock. They employ preachers known as Vandiran Apostates, or Shade Priests, which is a much cooler name than "Confessor."