Jer 37:1-21 The Babylonians temporarily lift the seige during 588BC and retreat from Jerusalem when an Egyptian army arrives to relieve the city.
Jeremiah then attempts to leave Jerusalem, ostensibly to secure the land he has recently bought from his uncle (see Jeremiah 32:1-15), but he is arrested at the Benjamin Gate on suspicion of deserting to the Babylonians: "Irijah refused to listen to Jeremiah, so he arrested Jeremiah and took him to the officers of Jerusalem. These rulers were very angry with Jeremiah and beat him. Then they put him in jail in the house of Jonathan the royal secretary, which had been made into a prison. So these people put Jeremiah into a cell in a dungeon, and Jeremiah was there for a long time." (Jeremiah 37:14-16)
Later, King Zedekiah gives orders for Jeremiah to be moved from the cell and confined to the palace courtyard.
The Dung Gate, Jerusalem (James Emery)
Jer 38:1-13 Jeremiah is once again accused of treason by the king's officials: "Then the officers said to the king, 'Jeremiah must be put to death! He is discouraging the soldiers who are still in the city, and all the people, by what he is saying to them. He does not want good to happen to us; he wants to ruin us'." (Jeremiah 38:4)
So the officers lower Jeremiah into a well in the guards' courtyard in an attempt to starve him to death. Jeremiah sinks down into the mud at the bottom. Ebed-Meleck, a Cushite eunuch in the palace, hears about the plot and tells the king. The king orders Jeremiah to be pulled out of the well as Zedekiah doesn't want the blood of LORD's prophet on his hands!
Jer 38:14-28 Zedekiah sends for Jeremiah to question him. Zedekiah promises not to kill Jeremiah if he answers truthfully. Jeremiah tells the king he will live if he surrenders to Nebuchadnezzar, and Jerusalem will not be burnt down; but if he refuses to surrender, he will be killed and Jerusalem will be destroyed.