PARIS — François Hollande defeated President Nicolas Sarkozy on Sunday, becoming the first Socialist elected president of France since François Mitterrand. Mr. Hollande campaigned on a gentler and more inclusive France, but his victory will also be seen as a challenge to the German-dominated vision of economic austerity as a way out of the euro crisis.

Mr. Sarkozy became the latest European leader to lose his post amid economic upheaval and the first French incumbent to be rejected since 1981.

In his five years in office, he propelled France, and himself, into a more central role in world affairs, rejoining the NATO military command and helping drive an international military campaign in Libya. He also proved to be a difficult but crucial ally of Chancellor Angela Merkel of Germany in their joint effort to master the European debt and currency crisis and save the euro.

That project, however, received multiple blows on Sunday, when Greek voters sent their own message against austerity. They handed the two main parties, both of which had pledged to follow harsh international bailout terms, significant losses as they streamed to parties on the far left and far right that have opposed budget cuts. In the process, voters cast into question the ability of any party to form a government soon, let alone continue with the austerity program.

The balance between reducing the debt and addressing popular anger is proving complicated for Europeans, and Mr. Hollande has said that he intends to give “a new direction to Europe,” demanding that a European Union treaty limiting debt be expanded to include measures to produce economic growth. Domestically, he has promised to raise taxes on big corporations and raise the tax rate to 75 percent for those earning more than one million euros a year.

The vote was viewed domestically as a rejection of Mr. Sarkozy and his relentless effort to appeal to the voters of the far-right National Front.

“I take the measure of the honor that’s been given me and the challenge that awaits me,” Mr. Hollande said before cheering supporters in the central French town of Tulle, which he represents in Parliament.

Mr. Hollande’s victory was narrow but undisputed. With 95 percent of the vote counted, official results showed him with 51.6 percent of the vote while Mr. Sarkozy, of the center-right Union for a Popular Movement, had 48.4 percent, The Associated Press said.

While thanking Mr. Sarkozy for his service to France, Mr. Hollande said: “Too many divisions, too many wounds, too many ruptures, too many cuts have separated our fellow citizens from one another. That’s all finished.”

After weeks of energetic, and at times bellicose, campaigning, Mr. Sarkozy was gracious in defeat. “François Hollande is the president of the republic, he must be respected,” Mr. Sarkozy said after calling Mr. Hollande to congratulate him. “I want to wish him good luck in the midst of these tests.”

Speaking earlier to party members, Mr. Sarkozy said that he would not lead the party into June’s legislative elections and that now, “I become a citizen among you.” He urged supporters not to give in to division, though, as he saw those elections as winnable for the party.

The French and Greek elections were closely watched in European capitals and particularly in Berlin, where Ms. Merkel has led the drive to cure the euro zone debt and banking crisis with deep budget cuts and caps on future spending. She spoke on the telephone with Mr. Hollande on Sunday night, congratulating him on his victory in the election, according to a statement by her spokesman, Steffen Seibert. Mr. Hollande has said for months that his first trip will be to Berlin.

But Ms. Merkel herself was embroiled in electoral politics on Sunday, suffering setbacks in elections in the state of Schleswig-Holstein, where her party appeared to be losing its hold on the state Parliament. With another election coming May 13 in North Rhine-Westphalia, Ms. Merkel is not viewed as having much room domestically to compromise on the critical issues of inflation and debt limits.

“How Hollande handles Merkel could make or break his prospects for the next five years,” said François Heisbourg of the Foundation for Strategic Research in Paris. “He has favorable circumstances, but she has domestic politics, too,” he said, and she is seen as likely to agree only to symbolic changes in the fiscal pact — not renegotiating it so much as adding clauses about growth to it.

Mr. Hollande, who may take over as president as early as May 14, will have little time to relax. He must travel to the United States for a meeting of the Group of 8 industrialized countries on May 18-19 and then a NATO summit meeting in Chicago on May 20-21, where he intends to make good on his promise to pull French combat troops out of Afghanistan by the end of this year, and where American and NATO officials will try to get him to change his mind.

Mr. Hollande’s victory will also have important implications for the right in France, with Mr. Sarkozy’s party already split between the prime minister, François Fillon, and the Sarkozy-like party leader, Jean-François Copé. The strong showing of Marine Le Pen of the National Front, who got nearly 18 percent of the vote in the first round of the presidential election, is a serious threat to Mr. Sarkozy’s party. It now must decide whether to make a deal with Ms. Le Pen for assembly seats in the second round of the legislative election; if not, the Union for a Popular Movement could lose up to 100 seats, political experts say.

Mr. Hollande campaigned on “change” and a more traditional presidency, where he would set the main course of policy but not micromanage day-to-day affairs, as Mr. Sarkozy did.

For the French, “it is a leap of faith that shows there is a strong will for a different policy course, not just at the national but at the E.U. level as well,” said Paul Vallet, a professor of history and political science at the Paris-based Institut d’Études Politiques.

The indebted countries of Europe are also hoping that Mr. Hollande can be a champion buying them more time to adjust. “Some countries in Europe are banking on that,” Mr. Vallet said.

Domestically, Mr. Hollande said he would raise taxes in a drive to balance the budget by 2017. He has vowed to raise the minimum wage, hire 60,000 more teachers over five years and lower the retirement age from 62 to 60 for manual workers who started their work as teenagers.

Voter turnout Sunday was about 81 percent of the 46 million registered voters, down from the 84 percent who participated in the last presidential ballot five years ago — the highest turnout since 1974.

The French, voting under gray skies with some rain, expressed a sharp desire for change and a better economic future.

Nicole Hirsch, a 60-year-old retiree in the working-class 20th arrondissement of Paris, said she was voting for Mr. Hollande in the hope that he would “bring the change that France needs.”

Claire, a 26-year-old engineer in Paris, agreed that change was needed, but still cast her ballot for Mr. Sarkozy. “I would like to believe in the Socialists’ sweet dream, but unfortunately, it is not going to happen,” she said, asking for privacy reasons not to use her last name. “Their program is unclear and not concrete.”

Pierre Marcus, a 59-year-old civil servant, said his vote for Mr. Hollande was motivated by a hope that a Socialist government would take steps to promote economic growth and soften the blow of the crisis on average citizens. “Five years of Sarkozy dismantled social institutions,” Mr. Marcus said. “I think that Hollande will reverse French politics in terms of employment and social issues.”

Sebastien Modat, 38, who works in marketing, stopped his jog to get a newspaper. “I found that Hollande had the power to bring people together,” he said. “The right was compelled to take up its traditional topics, creating tension among people.”

But the main question, he said, “is how we are going to resume growth.” He voted for Mr. Sarkozy five years ago, but on Sunday cast a blank ballot. “I hope there will be a change in mentalities and more consensus.”

Correction: May 7, 2012

A Web summary with an earlier version of this article erroneously stated that Mr. Sarkozy was the first French incumbent to be rejected since 1995. The last time a French incumbent lost re-election was 1981.