Iraq’s influential Shiite leader Muqtada al-Sadr took a step on Tuesday to try to defuse an eruption of violence in the capital, Baghdad, calling on his followers to stand down after at least 24 people were killed in two days of clashes with security forces.

The violence, after three years of relative stability in Baghdad, began shortly after Mr. Sadr declared on Monday on Twitter that he was quitting politics for good. His supporters went out to protest and stormed the heavily protected Green Zone in Baghdad, then came under fire from government security forces who included members of Iran-backed militias.

Mr. Sadr, appearing at a news conference on Tuesday in Najaf, a southern city holy to Shiite Muslims worldwide, called on his supporters to withdraw within the hour from the Green Zone, where most of the fighting has been focused, and said he was sorry about what had happened.

“Regardless of who started the sedition yesterday,” he said, referring to the violent clashes, “I say that my head is down and I apologize to the Iraqi people.” Mr. Sadr added that anyone who did not comply with his order would be considered no longer loyal to him. He also called on supporters to dismantle the protest camps they had maintained for weeks, including around Parliament.

Witnesses and Iraqi security officials confirmed that shooting had stopped in the Green Zone and that Sadr militia members and other supporters were withdrawing, some carrying tents they had used in sit-ins.

On Monday, Iraqi officials said at least 12 people had been killed. But the fighting continued overnight and into Tuesday, when a Health Ministry official said at least 24 people had been killed and more than 190 injured since Mr. Sadr’s supporters entered the Green Zone, home to Iraqi government offices, the United Nations and diplomatic missions including the US Embassy.

Baghdad began Tuesday under a strict curfew for the second straight day. But after Mr. Sadr’s announcement, Iraqi security commanders said they were lifting the curfew in the capital and in all the other parts of Iraq where it was in place.

The clashes have set Iraq on edge, with some fearing the country could descend into another violent phase after two decades of frequent fighting. Following the US invasion of Iraq in 2003, a sectarian civil war between Shiite Muslim and Sunni Muslim factions broke out, and was followed by a yearslong battle to drive out Islamic State after the terrorist group took over large parts of the country.

Although political turmoil and street protests are common in Iraq, this round of fighting laid bare the risk of an even more dangerous and unstable phase, fueled by political paralysis, divisions among the country’s Shiite majority and the breaching of state institutions.

In recent years, rivalries among Shiites have become the main driver of Iraqi political instability.

Iran-backed militias formed in 2014 to fight the Islamic State have become a permanent part of Iraqi government security forces, with some more answerable to Iran than the Iraqi government. Mr. Sadr, in contrast, is seen as an Iraqi nationalist and a thorn in the side of Iran and its continuing influence in neighboring Iraq.

Elections last year in October were seen as a fresh start for the country — a response to massive protests against a corrupt and dysfunctional government. Instead they have led to a political deadlock.

Mr. Sadr comes from a revered Shiite family of clerics and commands millions of followers in Iraq. His bloc won the most seats of any other party in Parliament in the October election, and he had tried in vain for months to form a coalition government with other partners after the elections. Frustrated over the failure, he urged his followers into the streets instead to achieve their aims.

The clashes over the past day mainly pitted Iran-backed paramilitary units that are part of Iraqi government security forces against armed members of Mr. Sadr’s paramilitary organization, the so-called Peace Brigades, attacking each other’s positions and offices, according to Sajad Jiyad, an Iraq-based fellow with the Century Foundation.

A senior Iraqi security official said some of those killed on Monday had been shot by pro-Iran militia members who are part of Iraqi security forces as they approached the home of the former prime minister Nuri Kamal al-Maliki. The official asked not to be identified because of the sensitivity of the issue.

Neighboring Iran, which has exerted extensive efforts over the past several years to bring Shiite factions in Iraq closer together, reacted with alarm to the fighting, closing its borders with Iraq and telling Iranians it would work to bring them home safely.

A spokesman for the US National Security Council said Monday that the United States was monitoring clashes but there was no current indication that the embassy would need to be evacuated.

The United Nations mission in Iraq called the clashes a dangerous escalation.

Falih Hassan, Nermeen al-Mufti and Awadh al-Taie contributed reporting from Baghdad