ATHENS — Antonis Samaras has worked his entire life to become prime minister of Greece. But now that he has achieved his dream job, the biggest question among both his friends and his enemies is how long he will be able to hold on to it.

On Wednesday, Mr. Samaras, the leader of the New Democracy party, was sworn into office, ushering in a new coalition government that will put Greece back at Europe’s bargaining table and ending a seven-week leadership vacuum that had destabilized this already fragile nation and cast a shadow over the euro zone’s future.

“I am fully aware of the critical moments we face as a country,” Mr. Samaras said during the transfer from the caretaker prime minister, Panagiotis Pikrammenos, adding that the Greek people were “injured” and needed “healing.”

But with Greece’s economy at a standstill and European leaders still uncertain about the country’s fate, Mr. Samaras, a pro-European nationalist known for his stubbornness as well as his tactical shrewdness, comes into power with little room for maneuvering and scant chance of comforting Greeks.

The new government can “incrementally develop a certain sense of stability and certainty, but it will always be vulnerable to any shock — whether political or economic,” said Marco Vicenzino, director of the Global Strategy Project, a geopolitical risk analysis firm based in London.

Mr. Samaras’s new role will require significant political contortion. Mr. Samaras, 61, must wrest enough concessions from Brussels in easing the terms of Greece’s austerity agreement to pacify the Greek public. Simultaneously, he needs to pursue root-and-branch changes to his nation’s sclerotic economy and dysfunctional government to persuade Germany and Greece’s other foreign lenders to keep Athens’s financial lifeline in place.

And he must do so while presiding over an unruly coalition that includes his longtime rivals, the Socialist party, Pasok, and a smaller left-wing party, who have little common ground besides a deep desire to prevent Greece from collapse.

While European leaders had publicly hoped for a victory by New Democracy over the more radical Syriza, which had pledged to renounce Greece’s bailout agreement, privately some officials say that Mr. Samaras will have to work hard to regain trust and good will, given his strident opposition to Greece’s first bailout deal and his weeks of foot-dragging last autumn before agreeing to go along with the second.

“He’s an awkward customer, more interested in himself than solving the crisis,” one European Union official in Brussels said on the condition of anonymity. “Now, of course, they’re the same thing, so we’ll work with him. He has a vested interest in making sure a bad situation doesn’t get worse.”

Many Greek voters switched parties to support Mr. Samaras as their last hope to save the country from ejection from the euro zone. Mr. Samaras ran on a platform promising to change the policy mix in the loan agreement by reversing some tax increases and rescinding cuts to pensions. But he did not convincingly specify where the extra money would come from in a country whose coffers are expected to run dry as soon as mid-July.

In some ways, Mr. Samaras has been vindicated. He steadfastly insisted that Greece needed more growth and that the austerity medicine prescribed by international creditors was making the country’s problems worse.

“Although he comes from the conservative background of New Democracy, he has an open mind on both sides of the spectrum,” said Chrysanthos Lazaridis, a member of Parliament from New Democracy and one of Mr. Samaras’s close advisers. As a trained economist, he added, Mr. Samaras favors “allowing market forces to do their job — without letting social cohesion unravel.”

Critics say that Mr. Samaras destabilized Greece with his insistence on calling elections to replace the government led by Lucas Papademos, the technocratic prime minister whose mandate was to sign Greece’s second loan agreement.

“He just wanted to be prime minister,” said Thanos Veremis, a political historian who said he voted for New Democracy as a last resort. “It was pure ambition, pure and simple. Even in this state of collapse, he wanted to be Nero, playing his harp.”

The new Greek government came together just a day before European finance ministers are to gather in Luxembourg on Thursday to discuss Greece’s latest troubles. George Zanias, the departing finance minister, is expected to represent Greece at the meeting, holding the fort for Vasilios Rapanos, the president of the National Bank of Greece, who is expected to be named Greece’s finance minister.

In a sign of the challenges the new government will face, Evangelos Venizelos, the Pasok leader and a former finance minister who negotiated Greece’s second debt deal, said his party would support the government in Parliament but not contribute any politicians to the new cabinet. That was clearly seen as an effort to avoid blame for any additional austerity measures. Leaders of the Democratic Left, the third coalition partner, made similar statements.

Some of those who know Mr. Samaras say he is ill equipped for the complex task of managing a coalition government. “He’s kind of stubborn in the sense that he’s not flexible and not a good negotiator,” said George Kirtsos, a high school classmate of Mr. Samaras who ran for office with the hard-right Popular Orthodox Rally party, which did not win enough seats to enter Parliament. “But that could change, of course.”

It already may have. “Samaras today is completely different than what he was two weeks ago,” Mr. Kirtsos said. “Two weeks ago, he was very negative about cooperating with Pasok.”

Educated at Athens College, an elite high school, Mr. Samaras, like many Greek politicians, has spent his entire career in office, with no experience outside government. He was first elected to Parliament at age 26 in 1976, after receiving an M.B.A. from Harvard Business School and an undergraduate degree in economics from Amherst College.

At Amherst, in Massachusetts, he lived in the same dormitory as George A. Papandreou, the former Socialist prime minister whose efforts to persuade Mr. Samaras to join an emergency coalition last June failed, soon toppling the government and setting off an acute phase of the euro crisis.

Since the fall of a military dictatorship in 1974, Greek politics has been dominated by three families — the Papandreou family for the Socialists and the Mitsotakis and Karamanlis families with New Democracy — that have alternated in power. Mr. Samaras has long played the role of the ambitious outsider.

As Greece’s foreign minister in 1992, Mr. Samaras signed the Maastricht Treaty, which set the criteria for the single currency. But that year, he was ousted from the government of Constantinos Mitsotakis for bitterly opposing allowing the former Yugoslav Republic of Macadonia to call itself Macedonia, the name of a bordering northern Greek region. (The issue still has not been resolved.) Mr. Samaras set up his own party, Political Spring, setting off the collapse of the Mitsotakis government in 1993.

Mr. Samaras then stayed on the sidelines of Greek politics for more than a decade, forming his own small party before returning to New Democracy in 2004 and rejoining the Parliament. In 2009, he defeated Dora Bakoyannis, the daughter of Mr. Mitsotakis, to become party leader. Last year, he kicked her out of the party for supporting the loan agreement, only to reconcile with her after the May 6 elections. Although his campaign rhetoric has often been fiery, in person Mr. Samaras is soft-spoken, reflective and a bit introverted.

Mr. Samaras is a descendant of two well-established families in Greece. His father was a cardiology professor, and his mother was the granddaughter of Penelope Delta, a beloved Greek writer who took her own life on April 27, 1941, the day the Nazis invaded Athens.

Mr. Samaras recounted that grim episode in a campaign speech on April 27, sounding a nationalist note that resonated with Greeks who believe the country’s loan deal represents a loss of sovereignty to Germany. In an election in which the neo-Nazi Golden Dawn party, known for its violent scuffles with immigrants, won 18 seats in Parliament, Mr. Samaras also tacked hard to the right on immigration issues. In his final campaign rally, he said that his party would kick illegal immigrants out of Greece’s public squares, as supporters waved Greek flags.

Martin Schulz, the president of the European Parliament and a German, captured Europe’s wariness toward the new Greek prime minister. “Mr. Samaras has not made himself known for his reliable comments,” Mr. Schulz told German public television. “In the past, he was one of those who rejected all reform measures proposed by George Papandreou.”

But Mr. Schulz said he believed Mr. Samaras was capable of forming a government that could work with European leaders. “I trust him to become a responsible partner,” Mr. Schulz said.

Much is riding on whether Mr. Samaras can pull together the two mainstream parties, New Democracy and Pasok, and forge a workable agreement with Europe and the International Monetary Fund.

“I think the future of both parties lies in this merger,” said Mr. Veremis, the historian. “If they fail to pull it off, they will both go down the drain under the Syriza onslaught.”

Reporting was contributed by Niki Kitsantonis from Athens, David Jolly from Paris, Paul Geitner from Brussels, and Melissa Eddy from Berlin.