BERLIN — German Chancellor Angela Merkel cleared the last major hurdle on her path to a fourth term Sunday, after members of the center-left Social Democrats voted in favor of continuing their governing coalition with her conservative bloc.

The decision ends almost six months of political uncertainty in Germany, the longest time the country has been without a government in its post-war history.

“I congratulate the SPD on this clear result and look forward to continuing to work together for the good of our country,” Merkel’s party quoted her saying on Twitter.

The Social Democrats had furiously debated whether to extend the so-called grand coalition of left and right for another four years after suffering a slump in last September’s election. In the end, almost two-thirds of the valid votes cast by the party’s 464,000 members favored a coalition deal with Merkel’s Christian Democrats and their Bavarian sister party.

Had the longtime German leader faced a “no” result, she would have been left with only two realistic options: forming a minority government or seeking a new election.

“This was a really important democratic decision for our country,” acting Social Democrat leader Olaf Scholz said in Berlin.

In the next few days, the Social Democrats will put forward six names — three women and three men — to lead the ministries they will control in the upcoming coalition, he said.

Parliament is expected to meet next week to elect Merkel as chancellor.

Merkel has worked since September, negotiating with rival parties to form a new government.

After September’s national election, which saw the Social Democrats received just 20.5 percent of the vote and the anti-migrant Alternative for Germany party come in third place, then-Social Democrats’ leader Martin Schulz ruled out another grand coalition with Merkel. This forced Merkel to negotiate with two smaller parties, one of which eventually rejected a deal.

Pressure from German President Frank-Walter Steinmeier prompted Schulz to rethink and weeks of haggling between his party and Merkel’s bloc resulted in a coalition agreement. Fewer Social Democrats approved the deal this time round than in 2013, when 76 percent backed a government with Merkel.

Many Social Democrats, particularly on the left, had argued that the party failed to make its mark on the last government and wouldn’t benefit from propping up Merkel for another term.

The head of the Social Democrats’ youth wing, Kevin Kuehnert, said he was disappointed by the outcome but insisted the membership ballot had resulted in an important political debate inside the party and beyond.

“The SPD needs to be more like it’s been in the last weeks and less like in the last years,” he said.

Dietmar Woidke, a member of Social Democrats’ national executive, said the new government can’t simply cite its strong economic record but needs to address the everyday concerns of voters that contributed to the rise of the right-wing Alternative for Germany, especially in the east of the country.

“The country has never been so successful, but there’s a lot of insecurity,” Woidke, who is also governor of the eastern state of Brandenburg, told The Associated Press. “If you don’t take care of people’s everyday worries, then you won’t reach them anymore.”

Follow the Bangor Daily News on Facebook for the latest Maine news.