TEL AVIV — Israeli President Reuven Rivlin on Wednesday tapped Prime Minister Benjamin Netanyahu of the right-wing Likud party to form a new government after receiving the final results of last week’s deadlocked election.

"The people of Israel don't want new elections," Rivlin said at the presidential residence in Jerusalem after handing the mandate to Netanyahu and passing over his primary challenger, former three-star general Benny Gantz from the centrist Blue and White party. "Parties will need to compromise."

Netanyahu, whose deal-making skills and alliances with right-wing and religious parties have helped make him Israel's longest-serving prime minister, now has six weeks to try to cobble together a government. If he fails to do so, the opportunity could pass to the next candidate who the president thinks has the greatest chance of forming a government.

Israeli presidents are responsible for picking prime minister candidates after elections. The process is usually a formality but has recently become much more complicated since neither Netanyahu nor Gantz was able to build a stable parliamentary majority on their own.

The announcement followed negotiations over a proposed unity government, with Gantz and Netanyahu unable to come to an agreement. Gantz — who is a former army chief of staff — has publicly resisted the idea of allying with the Likud, citing looming corruption charges against Netanyahu.

Netanyahu could be indicted on three separate charges of bribery, fraud and breach of trust.

Rivlin also floated the option of Netanyahu forming a government with Gantz as second-in-command, with the agreement that if Netanyahu is indicted he will step down until he is cleared of any wrongdoing.

Later, Gantz repeated his pledge not to serve under Netanyahu while he faced possible charges.

"Blue and White, led by me, does not agree to sit in a government whose leader is facing a severe indictment," he said. "This issue, among a number of other critical factors, is more important to us than any delegation of ministerial posts or a rotation."

Speaking after Rivlin, Netanyahu said: "I know that the only way to form a government is a unity one. We need unity to unify everyone and reconcile the people."

Benny Gantz, leader of Blue and White party, attends his election campaign event. Amir Cohen / Reuters

For Netanyahu, there is more than simply his political career at stake. If he manages to form a government, it may be possible for him to pass legislation that would grant him immunity. Israel’s attorney general is expected to decide whether to formally charge the prime minister by the end of the year, after a pretrial hearing Oct. 2.

Netanyahu, who failed to secure a clear election victory for the second time in five months, is running out of time to pass the legislation.

“Very shortly, these proceedings will begin making it virtually impossible for him to form a coalition government that would enable legislation to proceed that would stop those legal proceedings,” David Halperin, executive director of the center-left Israel Policy Forum, said.

The final results saw the Likud party add an extra seat in Parliament, raising its total to 32 out of the 120 seats, one behind Blue and White's 33. But since the Likud’s gain comes at the expense of an allied ultra-Orthodox party, it didn’t change the total of 55 lawmakers who support a Netanyahu government, compared to the 54 who back Gantz.

Former defense minister Avigdor Lieberman, who was tapped as the potential kingmaker after his nationalist Yisrael Beitenu party won eight seats, refused to endorse either candidate, meaning both Netanyahu's and Gantz's blocs were short of a 61 majority — the minimum needed to form a governing coalition in the 120-seat Israeli Parliament, or Knesset.

When Netanyahu failed to form a coalition government in May he dissolved Parliament, triggering last week's snap election, but as it stands it appears unlikely that he will have the numbers to usher in a third election.