JERUSALEM — Israeli Prime Minister Benjamin Netanyahu said Tuesday that his coalition struck a compromise to avoid taking the country to early elections.

Netanyahu's coalition partners were divided over a bill that would continue to grant exemptions from mandatory military service to ultra-Orthodox Jewish men, a divisive issue among Israelis.

The ultra-Orthodox parties demanded the government grant the exemptions. Rival religious and secular parties in the government threatened to bolt over the issue, potentially undermining Netanyahu's government, which holds 66 of the Knesset's 120 seats.

Under Tuesday's compromise, the five-seat secular nationalist Yisrael Beitenu party, which opposed the bill, will be allowed to vote against it. The bill is set to pass without the party's support.

"I said yesterday that I would make a final ultimate effort to prevent elections and maintain the good government under my authority," Netanyahu said in an address before parliament. "I promised and I fulfilled."

He thanked his coalition allies for "exhibiting responsibility so that we can continue leading with determination and success."

After Netanyahu's announcement, the Knesset voted against motions by the opposition to dissolve parliament and hold early elections.

The political showdown came as Netanyahu faces possible indictment on corruption charges. The opposition accused Netanyahu of manufacturing the crisis in order to force a new election. Early elections would have shifted attention away from his legal problems, and a win would have shored up his position ahead of a possible indictment.

Netanyahu has denied any wrongdoing in the cases against him, and has accused the police and media of a conspiracy to oust him.