Israel’s president has tasked Benjamin Netanyahu with forming a coalition government, throwing a lifeline to the incumbent prime minister after an inconclusive election threatened to end his political career.

Reuven Rivlin’s offer does not guarantee Netanyahu will lead Israel’s next administration. Before that can happen, Netanyahu has up to six weeks to forge a majority coalition in Israel’s parliament.

“The responsibility for forming the government will be handed to prime minister and Likud leader Benjamin Netanyahu,” the president’s office said in a statement.

With a divided Knesset, the 69-year-old leader now faces an uphill battle to secure support from at least 61 of 120 lawmakers. If his attempts fail, Rivlin could assign the task to someone else, most likely Benny Gantz, the leader of the opposition.

That scenario almost played out in May after Netanyahu failed to cobble together a coalition following a similar election result. But rather than give the opposition a chance to forge a government, he instead pushed to dissolve the Knesset, triggering repeat elections and giving himself another chance.

Many fear a third election will be called if the stalemate holds.

The president had been pushing the two main parties to put aside their differences and form a unity government as together they would have more than enough seats for a majority. Talks appeared to have stalled.

Domestic media speculated the Rivlin may have picked Netanyahu as a way of pushing the two to reach an agreement. The president could have waited up to a week to decide but his announcement adds pressure on Netanyahu to make political deals on a deadline or risk losing grip on power.

The prime minister has several potential routes to form a government, but many would require lawmakers from rival parties to defect. The clearest path would be to get support from Avigdor Lieberman, whose eight seats afford him a kingmaker status. However, Lieberman, a secular ultranationalist, has refused to sit in a government with religious parties, whose support Netanyahu also depends on.

Netayahu’s freedom is also potentially on the line. Next week, pre-trial hearings for three corruption cases against him are set to begin. If he retains the role of prime minister, he will not be required to step down, even if indicted. Netanyahu has denied all allegations.

The central election committee released an official vote tally on Wednesday from last week’s poll that confirmed an inconclusive, razor-thin margin between the two main parties, the ruling Likud and Blue and White.

Blue and White was one seat ahead, but neither party had enough support from lawmakers to form a majority coalition. Netanyahu, however, came out narrowly ahead of Gantz when Rivlin asked this week for all parliamentarians to endorse a candidate.

There is a precedent in Israel for political rivals to serve together after Yitzhak Shamir and Shimon Peres rotated the role of prime minister in the mid-1980s, each agreeing to serve two years.

Yet there was little optimism Gantz and Netanyahu could forge a unity government, as both men have demanded the top seat. Gantz, whose election campaign focused on toppling Israel’s longest-serving prime minister, has also repeatedly pledged not to ally with Netanyahu while he faces potential indictments.

Further complicating talks, Netanyahu also struck an agreement with rightwing and religious parties that back him to make sure they are part of any future government, something Gantz has sought to avoid.