HAVANA (Reuters) - Fidel Castro, the Cuban revolutionary who built a communist state on the doorstep of the United States and for five decades defied U.S. efforts to topple him, died on Friday. He was 90.

A towering figure of the 20th century and Cold War icon, Castro stuck to his ideology beyond the collapse of Soviet communism and remained widely respected in parts of the world that struggled against colonial rule.

Castro had been in poor health since an intestinal ailment nearly killed him in 2006. He formally ceded power to his younger brother, Raul, two years later.

Wearing a green military uniform, a somber Raul, 85, appeared on state television on Friday night to announce Fidel’s death, 60 years to the day since the two brothers and dozens of supporters left Mexico on a boat to take revolution to Cuba.

“At 10:29 at night, the chief commander of the Cuban revolution, Fidel Castro Ruz, died,” he said, without giving a cause of death.

“Ever onward, to victory,” he said, using the slogan of the Cuban revolution.

A mix of tributes and condemnation poured in from allies and foes around the world.

“History will record and judge the enormous impact of this singular figure on the people and world around him,” U.S. President Barack Obama said, extending “a hand of friendship” to Cuba.

Obama’s elected successor, Donald Trump, issued a blunt statement calling Castro “a brutal dictator who oppressed his own people for nearly six decades.”

“Fidel Castro’s legacy is one of firing squads, theft, unimaginable suffering, poverty and the denial of fundamental human rights,” Trump said.

Venezuela’s socialist president, Nicolas Maduro, urged revolutionaries to follow Castro’s legacy, while Chinese President Xi Jinping said “the Chinese people have lost a close comrade and a sincere friend.”

DECADES OF HOSTILITY

Raul Castro, who glorified his older brother, has nonetheless changed Cuba by introducing market-style economic reforms and agreeing with the United States in December 2014 to re-establish diplomatic ties and end decades of hostility.

It is unclear whether Trump, who takes office on Jan. 20, will continue efforts to normalize relations with Cuba or fulfill a campaign promise to close the U.S. embassy in Havana once again.

Fidel Castro himself offered only lukewarm support for the 2014 deal with Washington, raising questions about whether he approved of ending hostilities with his longtime enemy, a conflict that took the world to the brink of nuclear war during the Cuban Missile Crisis in 1962.

He did not meet Barack Obama when he visited Havana earlier this year, the first time an American president had stepped foot on Cuban soil since 1928.

Days later, Fidel wrote a scathing newspaper column condemning Obama’s “honey-coated” words and reminding Cubans of the U.S. efforts to overthrow the Communist government.

Cuba has declared nine days of mourning, during which time Castro’s ashes will be taken to different parts of the country. A burial ceremony will be held on Dec. 4.

There will be no top level games of baseball - Castro’s passion after politics - for the nine-day mourning period, the sport’s national federation declared.

Hundreds of students gathered in Havana on Saturday to honor Castro, and mass rallies are planned for the coming days.

“When I found out Fidel had died, I felt such pain. I cried,” said Badanys Rodriguez, 39, proudly showing off a tattoo on his shoulder of late Argentine revolutionary Ernesto “Che” Guevara, one of Castro’s closest comrades in the revolution.

However, in Miami, where many exiles from Castro’s government live, a large crowd waving Cuban flags cheered, danced and banged on pots and pans to celebrate the passing of a man they loathed.

MILITARY FATIGUES, CIGARS

The bearded Fidel Castro took power in a 1959 revolution and ruled Cuba for 49 years with a mix of charisma and iron will, creating a one-party state and becoming a central figure in the Cold War.

He was demonized by the United States and its allies for his repression of dissent at home and support of rebellion abroad, but admired by many leftists around the world, especially in Latin America and Africa.

Nelson Mandela, once freed from prison in 1990, repeatedly thanked Castro for his efforts in helping to weaken apartheid.

In April, in a rare public appearance at the Communist Party conference, Fidel Castro shocked party apparatchiks by referring to his own imminent mortality.

“Soon I will be like all the rest. Our turn comes to all of us, but the ideas of the Cuban communists will remain,” he said.

Transforming Cuba from a playground for rich Americans into a symbol of resistance to Washington, Castro crossed swords with 10 U.S. presidents while in power, and outlasted nine of them.

He fended off a U.S.-backed invasion at the Bay of Pigs in 1961 and claimed he survived or evaded hundreds of assassination attempts, including some conjured up by the CIA.

Wearing green military fatigues and chomping on cigars for many of his years in power, Castro was famous for long, fist-pounding speeches filled with blistering rhetoric, often aimed at the United States.

At home, he swept away capitalism and won support for bringing schools and hospitals to the poor. But he also created legions of enemies and critics, concentrated among the exiles in Miami who saw him as a ruthless tyrant.

“With Castro’s passing, some of the heat may go out of the antagonism between Cuba and the United States, and between Cuba and Miami, which would be good for everyone,” said William M. LeoGrande, co-author of a book on U.S.-Cuba relations.

Castro’s death - which would once have thrown a major question mark over Cuba’s future - seems unlikely to trigger a crisis as Raul Castro is firmly ensconced in power.

Fidel Castro no longer held leadership posts in his final years. He wrote newspaper commentaries on world affairs and occasionally met foreign leaders, but lived in semi-seclusion.

Still, the death of the man known to most Cubans as “El Comandante” - the commander - or simply “Fidel” leaves a void in the country he dominated for so long. It also underlines the generational change in Cuba’s communist leadership.

Raul Castro has vowed to step down when his term ends in 2018, and the Communist Party has elevated younger leaders to its Politburo, including 56-year-old Miguel Diaz-Canel, who is first vice president and the heir apparent.

Slideshow ( 13 images )

REVOLUTIONARY ICON

A Jesuit-educated lawyer, Fidel Castro led the revolution that ousted U.S.-backed dictator Fulgencio Batista on Jan. 1, 1959. Aged 32, he quickly took control of Cuba and sought to transform it into an egalitarian society.

His government improved the living conditions of the very poor, achieved health and literacy levels on a par with rich countries and rid Cuba of a powerful Mafia presence.

But he also cracked down on dissent, jailed his opponents, seized private businesses and homes, and monopolized the media.

Hundreds of thousands of Cubans fled the island.

“The dictator Fidel Castro has died, the cause of many deaths in Cuba, Latin America and Africa,” said Jose Daniel Ferrer, leader of the island’s largest dissident group, the Patriotic Union of Cuba.

Many dissidents settled in Florida, influencing U.S. policy toward Cuba and plotting Castro’s demise. Some even trained in the Florida swamps for the disastrous Bay of Pigs invasion.

But they could never dislodge him.

In 1962, the United States imposed a damaging trade embargo that Castro blamed for most of Cuba’s ills, using it to his advantage to rally patriotic fury.

Slideshow ( 13 images )

Over the years, he expanded his influence by sending Cuban troops into faraway wars, including 350,000 to fight in Africa. They provided critical support to a left-wing government in Angola and contributed to the independence of Namibia in a war that helped end apartheid in South Africa.

Castro also won friends by sending tens of thousands of Cuban doctors abroad to treat the poor and bringing young people from developing countries to train them as physicians.

‘HISTORY WILL ABSOLVE ME’

Born on Aug. 13, 1926, in Biran, eastern Cuba, Castro was the son of a Spanish immigrant who became a wealthy landowner.

Angry at social conditions and Batista’s dictatorship, Castro launched his revolution on July 26, 1953, with a failed assault on the Moncada barracks in the eastern city of Santiago.

“History will absolve me,” he declared during his trial.

He was sentenced to 15 years in prison but was released in 1955 after a pardon that would come back to haunt Batista.

Castro went into exile in Mexico and prepared a small rebel army to fight Batista, including “Che” Guevara.

On Nov. 25, 1956, Castro and a ragtag band of 81 followers set sail from the Mexican port of Tuxpan aboard an overloaded yacht called “Granma,” reaching Cuba in early December.

Only 12, including Fidel, Raul and Guevara, escaped a government ambush when they landed in eastern Cuba.

Taking refuge in the rugged Sierra Maestra mountains, they built a guerrilla force of several thousand fighters who, along with urban rebel groups, defeated Batista’s military in just over two years.

Early on, at the height of the Cold War, Castro allied Cuba to the Soviet Union, which protected the Caribbean island and was its principal benefactor for three decades.

The alliance brought in $4 billion worth of aid annually, including everything from oil to guns, but also provoked the 1962 Cuban Missile Crisis when the United States discovered Soviet missiles on the island.

Convinced that the United States was about to invade Cuba, Castro urged the Soviets to launch a nuclear attack.

Cooler heads prevailed.

Soviet leader Nikita Khrushchev and U.S. President John F. Kennedy agreed the Soviets would withdraw the missiles in return for a U.S. promise never to invade Cuba. The United States also secretly agreed to remove its nuclear missiles from Turkey.

‘SPECIAL PERIOD’

When the Soviet Union collapsed in 1991, an isolated Cuba fell into an economic crisis that lasted for years and was known as the “special period.” Food, transport and basics such as soap were scarce and energy shortages led to frequent and long blackouts.

Castro undertook a series of tentative economic reforms to get through the crisis, including opening up to foreign tourism.

The economy improved when Venezuela’s late socialist leader, Hugo Chavez, who looked up to Castro as a hero, came to the rescue with cheap oil. Aid from communist-run China also helped, but Venezuelan support has eased since Chavez’s death in 2013.

Plagued by chronic economic problems, Cuba’s population of 11 million has endured decades of hardship, although not the deep poverty, violent crime and government neglect of many other developing countries.

Cuban state workers earn on average the equivalent of $25 a month and struggle to make ends meet even in an economy where education and healthcare are free and many basic goods and services are heavily subsidized.

Still, for most Cubans, Castro has been the ubiquitous figure of their lives.

Many love him and share his faith in communism, and even some who abandoned their political belief still respect him.

“For everyone in Cuba and outside his death is very sad,” said Havana resident Luis Martinez. “It is very painful news.”