CARACAS, Venezuela -- Opposition leader Leopoldo Lopez was released from prison and placed under house arrest Saturday after more than three years in a military lockup, a shock reversal by the government that fueled hopes for a broader amnesty for dozens of jailed activists in a country sliding ever deeper into political turmoil.

A euphoric Lopez briefly greeted a few dozen supporters gathered outside his home in Caracas in the afternoon. Climbing atop a wall dressed in a white shirt, he clutched and then kissed a Venezuelan flag and raised his right fist in a show of defiance.

Lopez vowed that he is prepared to return to jail rather than give up his fight to remove socialist President Nicolas Maduro.

"This is a step in the march toward freedom," Lopez said in a statement read by close ally and lawmaker Freddy Guevara. "I carry no resentment, nor will I give up my beliefs. My position against this regime is firm as are my convictions to fight for a real peace, coexistence, change and freedom."

Venezuela's government-stacked Supreme Court said in a statement that it granted Lopez the "humanitarian measures" for health reasons and also for "serious signs of irregularities" in the handling of the case that it did not specify.

As his backers celebrated, relatives of dozens of other jailed activists gathered at a jail in Caracas run by Venezuela's intelligence police in hopes that their loved ones might also be released in the coming hours.

Speculation that Lopez's pre-dawn transfer may have been part of a larger deal was sparked in part by a government truth commission statement saying that as part of its work to defuse tensions, it had asked the judicial system to evaluate applying "alternative formulas" for those imprisoned for violent acts.

The opposition has been demanding the release of dozens of activists it consider political prisoners in order to initiate talks aimed at resolving a three-month-old political crisis that has left more than 90 people dead and hundreds injured.

But Lopez, the most prominent and rebellious of those behind bars, was seen as the last person likely to leave jail, and the opposition went to lengths to dismiss talk that it had secretly offered anything in return for the government concession. Some government supporters expressed dismay over his release.

The 46-year-old former Caracas-area mayor was sentenced in 2015 to nearly 14 years in prison after being convicted of inciting violence during anti-government protests in which three people died and dozens were wounded.

"We spoke for like 40 minutes. He's hugging his children, he's with his wife. .... I'm sure they are celebrating," Lopez's father, who shares his son's name, said from exile in Spain. He said in recent days Lopez had been isolated in his prison cell without food and attributed his son's transfer to international pressure on Maduro's government.

"He told me himself recently: 'Dad, it's always darkest right before the break of dawn,"' the elder Lopez added.

Venezuela has been rocked by near-daily protests since late March, fueled by widespread discontent over shortages of basic goods, galloping inflation and allegations that Maduro is undermining democracy in the country.

Spanish Prime Minister Mariano Rajoy was the first to break the news of Lopez's transfer, which was brokered by his predecessor, Jose Luis Rodriguez Zapatero. Zapatero has been travelling back and forth to Venezuela for months trying to secure the release of jailed opposition leaders and jumpstart dialogue between the government and opposition.

The Supreme Court statement pointing to possible "irregularities" in the Lopez case surprised government supporters and foes alike because the high court has not previously shown any signs of misgivings about its rulings. Some suggested it may have been a slight aimed at chief prosecutor Luisa Ortega Diaz, a longtime government loyalist who oversaw the trial against Lopez but is now being lionized by the opposition for her break with Maduro over his push to rewrite Venezuela's constitution.

Foreign governments and human rights groups have long criticized Lopez's detention as politically motivated, and one of the prosecutors on the case who later sought asylum in the United States said he was ordered by the government to arrest Lopez despite a lack of evidence. The judge in the case was later sanctioned by the Obama administration.

But Maduro and his supporters said the decision in no way exonerated Lopez or the opposition for attempts to destabilize the government.

"You know the deep and profound differences I have with Mr. LL," Maduro said at a televised event, referring to Lopez by his initials. "After almost four years in Ramo Verde (prison) hopefully this measure will be understood and he'll send a message in support of peace, because that's what the country wants."

Concern about Lopez's health had been growing after reports in May that he had been hospitalized in very serious condition. More recently, supporters claimed he was being tortured and held in solitary confinement for 32 days for his refusal to call for an end to the latest protests against Maduro -- claims the government has denied.

But in his brief appearance before supporters Lopez exhibited a muscular physique honed from exercise in jail.

Lilian Tintori, Lopez's wife, has campaigned in Venezuela and abroad to try to win freedom for her husband and met with President Donald Trump in February. Afterward Trump tweeted a photo of the Oval Office encounter and called for Lopez to be released "immediately." The White House on Saturday welcomed Lopez's release from prison but said more needs to be done to clear his name and that of other prisoners held unfairly by the Maduro "regime."

"This is a major capitulation by Venezuela's government, which just days ago allowed armed thugs to assault the National Assembly and beat up opposition lawmakers," said Jose Miguel Vivanco, Americas director at Human Rights Watch. "It's a sign that the massive street protests -- plus the calls by democratic leaders throughout Latin America to end the repression -- are having an impact."

------

Associated Press writers Joshua Goodman in Bogota, Colombia, and Joseph Wilson in Barcelona, Spain, contributed to this report.