JERUSALEM — Hundreds of Palestinian prisoners agreed to halt a weekslong hunger strike Monday in exchange for promises of better conditions, ending a standoff that left several participants clinging to life and drew thousands of Palestinians to the streets in shows of solidarity.

The Palestinians won key concessions in a deal mediated by Egyptian officials, including more family visits and limits to a controversial Israeli policy that can imprison people for years without charge.

In return, Israel extracted pledges by militant groups to halt violent activities, and prevented the potentially explosive scenario of prisoners dying of hunger.

The fate of the prisoners is deeply emotional for Palestinians; nearly everyone has a neighbor or relative who has spent time in an Israeli jail. Hundreds of Palestinians took to the streets of the West Bank and the Gaza Strip each day to show solidarity with the inmates, often holding pictures of their imprisoned loved ones.

In Gaza City, Palestinians cried for joy and praised God over blaring loudspeakers upon news of the deal. “God is Great! To God is our thanks!” they chanted.

Thousands waved the colorful Palestinian flag, distributed sweets and prostrated themselves in thanks. The deal ended one of the largest mass strikes of Palestinian prisoners.

Two men launched the strike Feb. 28, refusing food for 77 days, becoming the longest ever Palestinian hunger strikers. At least 1,600 Palestinian prisoners, more than a third of the prison population, joined the strike April 17, fasting for 27 days.

With the Palestinians already planning mass demonstrations for their annual day of mourning today, both sides were eager to reach agreement to avoid spreading anger over the issue. Palestinians use May 15 to commemorate their suffering that resulted from Israel’s establishment 64 years ago, a day they call the “nakba” or “catastrophe.”