The agreement ended a tense stand-off that left 33-year-old Khader Adnan clinging to life and drew international attention to a controversial Israeli policy of holding suspected Palestinian militants without charge.
The hunger strike also turned Mr Adnan, a member of the Islamic Jihad militant group, into a hero for Palestinians.
Under the deal struck with military prosecutors, he agreed to resume eating immediately, the Israeli justice ministry said.
Outside the Jerusalem high court, two dozen demonstrators waved the Palestinian flag and chanted “Khader is coming home”.
Mr Adnan was a spokesman for Islamic Jihad, a group that has killed dozens of Israelis in suicide bombings and other attacks. It is not known whether he participated in violent acts.
The statement said that if “no new additional substantial evidence” emerges against him, he would be released on Apr 17.
It means his four-month detention order will be counted from the day of his arrest, not the day it was issued several weeks later. The deal also suggests that military prosecutors will not seek extensions, which can often be used to prolong administrative detentions.
The justice ministry said that Mr Adnan, who remained in hospital, accepted the deal through his solicitor.
The deal was denounced by Israel’s hardline foreign minister, Avigdor Lieberman. “It was a wrong decision to release the Jihad activist,” he said. “But it is our duty to respect and honour every supreme court decision even when we don’t agree with it.”
Mr Adnan’s supporters and physicians said in recent days that he could not survive much longer on his hunger strike. Doctors who treated him said he lost about 60lb, his hair was falling out, his skin had turned yellow, and he was in danger of a heart attack.