THREE YEARS ago, Turkey and Brazil were the envy of much of the world. They were emerging powers with booming economies and dynamic, democratically elected leaders. They were exerting considerable influence in the regions around them, often being cited as models. And they were developing global ambitions: The presidents of the two countries dabbled in Israeli-Arab diplomacy and joined in an attempt to broker a deal with Iran on its nuclear program.

Now, suddenly, the streets of both countries have filled with hundreds of thousands of angry demonstrators, many of them the young, middle-class products of their countries’ takeoff. What gives? Though there are some big differences between Turkey and Brazil (to which we’ll return), it’s not hard to find common factors behind this explosion of popular unrest.

Perhaps the most important is the disregard by the countries’ political elite for many of their citizens. After 12 years in power, Turkish Prime Minister Recep Tayyip Erdogan has grown arrogant and autocratic-minded; he dismisses the legitimate concerns of secular Turks who differ with his Islamist agenda, as well as sectarian minorities worried by foreign policies that look like a pro-Sunni agenda. Brazilian President Dilma Rousseff’s Workers’ Party, in office for a decade, has tolerated pervasive corruption and budgeted billions for the 2014 World Cup and the 2016 Olympics even while basic services such as education, health and public transportation remain far below the par of Brazil’s peers.

Both governments made the mistake of employing violence in response to protest. A humdrum demonstration over bus fares in Brazil’s largest city, Sao Paulo, exploded into a nationwide movement after riot police brutally attacked peaceful marchers with tear gas, stun grenades and rubber bullets. In Turkey, the repression has been far worse: Police have launched repeated attacks to clear Istanbul’s Taksim Square and are now conducting sweeps to detain organizers of the ­protests.

Both countries also suffer from democratic underdevelopment. Opposition parties are weak and don’t offer a plausible alternative; Ms. Rousseff is still favored to win reelection, and Mr. Erdogan is preparing constitutional changes that would allow him to slide from prime minister to president. Turkey’s media have been cowed, and many Brazilian protesters have been angered by what they see as one-sided coverage by their big corporate television networks.

Some people in both countries hope that what is happening will ultimately strengthen democracy. There’s a much better chance of that in Brazil, where mayors in several cities have reversed the hated bus fare increases. To her credit, Ms. Rousseff issued a statement saying that “those who took to the streets delivered a message to society as a whole and most of all to government” and proved “the energy of our democracy.” Mr. Erdogan took a step in the same direction by meeting with some protesters and offering concessions — but then sent police back after the protesters and their leaders. His hard-line approach has darkened Turkey’s prospects and its image as a moderate Muslim democracy.