The months-long crisis in Israel’s medical system finally came to an end early Thursday morning, after representatives of the medical residents and the Treasury finally signed an agreement.

Channel 2 News reported that the agreement was drafted until the wee hours of the night at the offices of the Israel Medical Association in Ramat Gan, and was signed shortly before 4:00 a.m. (Israel time).

The agreement does not include opening for renegotiation the collective agreement signed between the Israel Medical Association in August. The residents were opposed to the agreement because it did not deal with their problems – specifically the extra shifts and extended hours many of them are required to take on, for very low pay.

However, while the collective agreement will not be renegotiated, the agreement signed by the residents will include a review of the collective agreement in 2015.

The parties also agreed to establish enforcement mechanisms to make sure that the number of duties by rotation residents will be required to work shall not exceed six per month. In addition, residents will receive grants payable during their internships. The full terms of the agreement will be disclosed in a press conference on Thursday morning, IDF Radio reported.

On Monday night, the sides drafted a document of principles which was brought for approval by residents. 269 voted in favor of the document and 163 were against, mostly from the Ichilov Hospital in Tel Aviv.

Over the past few months, the residents repeatedly tried to resign from their jobs due to their dissatisfaction with the collective agreement. The Labor Court ruled that the mass resignation was illegal, leading many residents to simply walk off their jobs.

The issue later came before the Supreme Court, which on November 17 gave the residents three days to decide whether they are willing to re-negotiate with the Treasury for a period of two weeks. The residents agreed, paving the way for negotiations with two mediators appointed by the court. The mediators, former Supreme Court Justice Professor Yitzhak Zamir and President of the Israeli Association of Mediators Professor Moti Mironi, are credited with bringing the two sides together and alllowing for an agreement to be reached.