Speaking generally, since the question does not call for specific cases, democratic systems are no more or less inherently safe against abuses of power than are dictatorships. At the end of the day, if the government does not act to curb its own behavior, then its behavior will not be effectively curbed. Democracies all over the world, current and historical, have overseen barbarity in dizzying variety.
With that disclaimer out of the way, there are several conventional attempts to prevent these abuses that have common themes.
1 - Bills of Rights: Establishing a priori rights and codifying such in law is the most common. In the United States (where my expertise is), the key rights are in the 4th, 5th, and 14th Amendments - which collectively make it a violation of the Constitution for the government to create conditions which are functionally equivalent to those resulting from a guilty verdict unless it first provides due process of law; i.e. a trial by a jury of one's peers in a court of law wherein you have competent legal representation. Those same amendments limit those rights to citizens, however, so foreign nationals do not enjoy these protections (though they may frequently receive them anyway).
In the EU, Title I of the Charter of Fundamental Rights accomplishes much the same.
2 - Protection of Provocative Behaviors: In the U.S. these are provided by the 1st, 2nd, and 9th Amendments which protect free assembly, free speech (even that speech which would otherwise scare the pants off a government), the keeping of weapons, and the benefit of ambiguity and doubt, respectively. This is not as as strong as #1, because there have always been acknowledged limits to these rights: The right to free speech does NOT mean you have a Constitutional right to yell "FIRE!" in a crowded theatre unless there is an actual fire that threatens those within; nor are you allowed to say things like "Let's kill the Vice President" regardless of reason. The ambiguity as to where exactly that line is leaves the government room to declare certain acts, certain kinds of weapons, or certain presumed rights to be out of bounds. But the presence of these kinds of declarations and prior protections for this type of behavior means the government will at least have to fight for their interests in the matter.
3 - Oversight: Easier said than done, oversight means that no one part of the government is permitted to act entirely on its own. Even if it's only post facto review, the fact that a government actor will have to answer for the choices they made is a powerful deterrent to bad faith actions. The trick is to get the oversight into the hands of a party who has no stake in the actions of the government or, failing that, has conflicting interests. In the United States this is a reason for so-called 'Miranda Rights', particularly your right to an attorney: the defense attorney's job is to act as a form of oversight and make sure that juries don't have to listen to a prosecutor with no regard for the truth. This is also why Congress and its various committees are set in adversarial relationships with the Executive and the Judiciary. Nothing inspires zealous oversight quite like hostility.
In democracies, the overseer of last resort is the electorate. But if that electorate becomes culturally comfortable with abuses of power, then they offer no more resistance than the compatriots of a dictator. This is why I open with the note that democracies don't offer any kind of structural protection in and of themselves.
Still, the role that citizens play as overseers can be strengthened, and in the U.S. a commonly used example of this is the Freedom of Information Act (FOIA), where common citizens may legally demand disclosure of otherwise non-public documents that show how the government has acted.
And even in cases like accusations of terrorism, wherein secret information and assets are at risk of exposure, the U.S. has at least attempted to create an advocate for citizen rights in the form of the FISA Court. FISA's success at curbing abuses is highly controversial, of course.