Chancellor Angela Merkel finally reached a deal Wednesday to form a new German coalition government, handing the powerful finance ministry to the country's main center-left party in an agreement aimed at ending months of political gridlock.

The center-left Social Democrats' leaders now have one last major hurdle to overcome — winning their skeptical members' approval of the deal.

Merkel's conservative Christian Democratic Union, its Bavaria-only sister, the Christian Social Union, and the center-left Social Democrats agreed after a grueling final 24 hours of negotiations on a 177-page deal that promises "a new awakening for Europe."

"I know that millions of citizens have been watching us closely on this long road over recent weeks," Merkel said. "They had two justified demands of us: First, finally form a government — a stable government — and second, think ... of people's real needs and interests."

The coalition deal could be "the foundation of a good and stable government, which our country needs and many in the world expect of us," she added.

Germany has already broken its post-World War II record for the longest time between its last election on Sept. 24 to the swearing-in of a new government. That is still at least several weeks away.

Merkel currently leads a caretaker government, which isn't in a position to launch major initiatives or play any significant role in the debate on the European Union's future, led so far by French President Emmanuel Macron.

A key role in the EU is particularly dear to Social Democrat leader Martin Schulz, a former European Parliament president.

On Wednesday he declared that, with the coalition deal, Germany "will return to an active and leading role in the European Union." The agreement states, among other things, that Germany is prepared to pay more into the EU budget.

To help that process, Schulz announced later he would hand over his party's leadership to Andrea Nahles, the head of its parliamentary group, and take on the role of Germany's foreign minister. Nahles will still have to be confirmed by the party.

The coalition accord will be put to a ballot of the Social Democrats' more than 460,000 members, a process that will take a few weeks. Germany's highest court said Wednesday it had dismissed a series of complaints against the ballot.

Many Social Democrats are skeptical after the party's disastrous election result, which followed four years of serving as the junior partner to Merkel's conservatives in a so-called "grand coalition." The party's youth wing vehemently opposes a repeat of that alliance.

If Social Democrat members say no, the new coalition government can't be formed. That would leave only an unprecedented minority government under Merkel or a new election as options.

Schulz had previously ruled out taking a Cabinet position under Merkel, and his decision to become foreign minister may complicate his efforts to sell the coalition deal to party members.

"We are optimistic that we can convince a wide majority of our members to enter this coalition," he said, speaking with Nahles at his side.

Schulz's zigzag course has undermined his authority. He vowed to take the party into opposition on election night, but reversed course in November after Merkel's efforts to build a coalition with two smaller parties collapsed.

On the conservative side, Merkel needs only the approval of a party congress of her CDU, a far lower hurdle.

"I am counting on convincing our members that we have negotiated a very good coalition agreement," Schulz said.

His party reached compromises on two key demands: curbing the use of temporary work contracts in larger companies and at least considering narrowing differences between Germany's public and private health insurance systems.

In addition to the Foreign Ministry, the Social Democrats are set to get the Labor and Finance Ministries — the latter a major prize, held by Merkel's CDU for the past eight years and an influential position given Germany's status as the eurozone's biggest economy. Unconfirmed reports in the German media say the new finance minister and vice chancellor would be Olaf Scholz, Hamburg's center-left mayor.

The Interior Ministry, also held by the CDU, would go to Bavaria's CSU, which has pushed hard to curb the number of migrants entering Germany.

Merkel's party would keep the Defense Ministry and get the Economy and Energy Ministry, held by the Social Democrats in the outgoing government. One CDU lawmaker, Olav Gutting, wrote on Twitter: "Phew! At least we still have the chancellery!"

Merkel defended the carve-up of ministries.

"Of course, after many years in which Wolfgang Schaeuble led the finance ministry and really was an institution, many find it difficult that we can no longer hold this ministry, and the same goes for the interior ministry," she said. "But we have important jobs. We have the economy ministry for the first time in decades."

She dismissed suggestions that Social Democrat-led ministries would force her to open Germany's purse wider for Macron's European reform proposals than she would like.

"Regardless of whether a ministry is led by the Social Democrats or the (Christian Democratic) Union, you can only spend the money you have," Merkel said.

If the coalition comes together, the nationalist Alternative for Germany will be the biggest opposition party. Co-leader Alexander Gauland criticized the deal, particularly the possibility of deeper European financial integration.