Short in stature with big square glasses, Daniel Ortega did not resemble a typical military strongman when he first caught the world's attention in the 1980s.

Yet as the leader of Nicaragua's left-wing Sandinista revolution, he was credited with first bringing down a dictator, and then the US-sponsored rebels, who tried to block his move into legitimate power.

Now in 2018, almost four decades later, he is serving his third consecutive term as president, while fighting new battles. Large-scale protests against his presidency have plunged the country into turmoil and led to hundreds of deaths.

To his supporters, he remains a true patriot; they call him Comandante Daniel, with a mix of reverence and affection. Some have taken to the streets in his name, forming brutal paramilitary gangs to crack down on any signs of dissent.

His critics, who include many former allies, say he has become a corrupt and authoritarian ruler, turning his back on his revolutionary ideals and coming to resemble the dictator he deposed. They have also taken to the streets; some peacefully, some throwing homemade mortars.

How did he rise to the top?
Daniel Ortega, the son of a shoemaker, was still a teenager when he joined the left-wing Sandinista National Liberation Front (FSLN).

The group was fighting against the dictatorship of Anastasio Somoza, whose family had ruled the country since 1936.

In the 1960s, the young Ortega dropped out of a law course to fully commit to the cause. While still in his twenties, he held up a branch of Bank of America in the capital, Managua, with a machine gun, in a bid to raise funds. He was arrested and severely tortured during seven years in jail.

In 1974, he secured an early release - along with other Sandinistas - in exchange for hostages. The deal involved him being sent to Cuba, but he used this as a chance to train in guerrilla warfare and then snuck back into his homeland, where the peasant-led uprising was about to turn into a full-scale civil war.

The Sandinistas took power in 1979, forcing President Somoza into exile. Mr Ortega was elected as his successor in 1984, after serving on the Sandinista's five-member "national reconstruction" board.

Why did the US want to stop him?

Most international observers recognised the 1984 election as generally free and fair, despite opposition complaints.

However, US President Ronald Reagan dismissed it as a "sham" and stepped up his support for armed counter-revolutionary groups known as Contras.

This was the height of the Cold War, and Washington saw the Sandinistas as a front for Soviet and Cuban-style communism and a threat to US-backed governments throughout Central America.

Tens of thousands of Nicaraguans died in the Contra war, and the International Court of Justice (ICJ) later ruled that the US had violated international law in its intervention.

The first downfall
Despite having made important gains, particularly in health, education and land reform, the first Sandinista government came under criticism for economic failures.

The impact of the Contra war and US sanctions made economic reconstruction impossible.

In the 1990 presidential elections, Mr Ortega was defeated by liberal opposition candidate Violeta Chamorro, a former close associate who broke away from the increasingly radical Sandinistas and who formally ended the war.

A combination of corruption allegations and deep splits within the Sandinista movement led Mr Ortega to suffer two further election defeats in 1995 and 2001.

In between the two campaigns, his stepdaughter Zoilamérica Narváez accused him of repeatedly raping her as a child.

Mr Ortega denied it and avoided trial by invoking his immunity as a member of congress. His wife Rosario Murillo - a poet he met while in prison - stood by him, saying her daughter's claims were shameful.

Both Mr Ortega and Ms Murillo's personal reputations were severely damaged by the scandal.

The transformation
In 2006, Mr Ortega made an unexpected comeback by moving away from his staunch communist roots, saying he would seek foreign investment to ease widespread poverty. (Forbes ranks Nicaragua as the second poorest country in the Western hemisphere.)

In a campaign masterminded by his wife, the black-and-red Sandinista flags were largely replaced by pink campaign posters; the olive-green military uniform was exchanged for collarless white shirts, and the Marxist slogans were swapped for a vague commitment to "Christianity, Socialism and solidarity".

"Jesus Christ is my hero now," he said, playing to the highly religious population.

Days before he was elected, he stoked further controversy by refusing to oppose a complete ban on abortion, which earned praise from Catholic and evangelical leaders but angered liberal voters and rights groups. The law remains in place in 2018.

The tightening grip
In 2009 Nicaragua's Supreme Court removed constitutional obstacles to allow Mr Ortega to stand for another term - a move the opposition condemned as illegal.

Further constitutional changes were made to allow him to run for a third consecutive term in 2016.

Many boycotted the vote, saying it was unfair as the opposition had been quashed. However, Mr Ortega insisted the changes were necessary for the country's stability.

He picked his wife as his 2016 running mate. As vice-president, Ms Murillo is the more vocal of the two, often giving long speeches on television.

The uprising
In April 2018, pro-government groups violently crushed a small demonstration against reforms to Nicaragua's pension system.

The outcry among Mr Ortega's critics caused the movement to spiral into a popular call for his resignation.

As the violence continued, a university student received widespread attention for standing in front of Mr Ortega in a televised debate and calling him a murderer.

By July, human rights groups said the number of people killed in protest-related violence had exceeded 300.

Mr Ortega resisted calls to step down or call an election. Ms Murillo blamed the crisis on "an invasion... of evil spirits which want evil to reign in Nicaragua".