Park Geun-hye spent part of her childhood in South Korea’s presidential palace, raised by an autocratic father who seized power in a military coup 51 years ago. She returns now as the democratically elected president of a nation concerned about its slowing economy and mounting social problems.

With her narrow victory in Wednesday’s election, Park, 60, becomes an unlikely leader: She’s the first female president in a nation dominated by men, and she’s a conservative selected by voters to address their largely left-leaning wishes, including greater engagement with North Korea and a major expansion of government welfare spending.

She was also elected because she convinced South Korean voters that she could heal some of the scars of her father’s 18-year rule — a period of hypercharged economic growth, but also one in which dissenters were tortured, jailed and sometimes killed.

In a race that wasn’t decided until after several hours of vote counting, Park edged out former human rights lawyer Moon Jae-in, who conceded just before midnight local time. With the ballots counted Thursday morning, Park had received 51.6 percent of the total, compared with Moon’s 48 percent.

“I believe the nation’s passion to overcome crisis and revive the economy has brought this victory,” Park said during a late-night victory speech in downtown Seoul. “I will not forget your trust in me.”

The two leading candidates had proposed comparable policies, their major plans differing only in degree and projected cost. The race, instead, became a referendum on their backgrounds, with Park cast as the “princess” and Moon as the “common man,” said Hahm Sung-deuk, a political scientist at Korea University.

The debate about Park’s family legacy revealed a generational rift. Park received overwhelming support from those 50 and older. Moon garnered votes from those in their 20s and 30s. The two fought over the middle ground — those in their 40s who remember the frenzied student protests for democracy in the 1980s, but who now worry about the soaring cost of educating their children, as well as the shrinking job market those children will face when they graduate.

South Korea has the world’s 15th-largest economy, but its boom days are over, with just 2.4 percent growth predicted this year by the central bank. That is far below the 7 percent growth promised by current President Lee Myung-bak, a conservative who five years ago laid out a raft of ambitious targets, none of them realized.

In Washington, President Obama congratulated Park on her victory and said he looked forward to working with her administration. The U.S.-South Korean alliance “serves as a linchpin of peace and security in the Asia Pacific,” he said, noting the two nations’ “deep economic, security, and people-to-people ties.”

Park will replace Lee in February to begin a single five-year term.

Conservative and liberal voters alike say the government must do more to help the people. South Korea spends the second least on welfare, as a percentage of gross domestic product, among industrialized countries. The income gap, though close to average for a first-world country, is widening. Park, on the campaign trail, has pledged to cut college tuition in half, expand state-sponsored child-care programs and provide full coverage for major diseases.

All of that will cost $125 billion, an amount Park’s Saenuri Party says can come from closing tax loopholes, ending wasteful spending and reforming the government. But no tax increases are planned, and Park, in a recent debate with Moon, stumbled over a question about how her welfare programs would be funded. The Dong-A Ilbo, a major conservative daily newspaper, wrote in a recent editorial that both Park’s and Moon’s social welfare plans were “nothing more than empty promises without feasible financing methods.”

South Korea is a notably egalitarian nation, in large part, perhaps, because its citizens remember a time when everybody was equal — and poor. When Park’s father, Park Chung-hee, seized power in a 1961 military coup, the average South Korean earned $100 a year.

Park Chung-hee’s 18 years in power transformed South Korea. He was criticized for human rights violations, but he also created the blueprint for affluence, giving low-cost loans to big corporations and promising them government support. It was that cooperation that turned Samsung and Hyundai into giants.

When Park Geun-hye was 22, her mother was assassinated by North Korea-backed agents. She became de facto first lady for five years, a role that ended in 1979, when her father was assassinated by his intelligence chief. Park has never married and says she has devoted her life to her country.

Park was first elected to South Korea’s National Assembly in 1998, and as party leader this year, she led a surprising victory in a parliamentary election. She also had to tack away from fellow party member and current president Lee, a former Hyundai executive who favored big business and drew a hard line in dealings with Pyongyang. Lee will leave office with an approval rating near 20 percent.

Park’s job, political analysts say, is to find a middle ground between Lee and the liberals. Park says that she will be tough on conglomerate executives who break the law, rather than pardoning them as Lee often did, but that she won’t try to curtail the power of the families that run the conglomerates, as Moon proposed.

On relations with North Korea, Park says she will restore some of the joint economic projects and humanitarian aid that Lee cut off. But she also says that sustained dialogue — including a possible summit with the North’s leader, Kim Jong Eun — hinges on Pyongyang living up to its commitments to end its nuclear weapons program.

Yoonjung Seo contributed to this report.