LONDON, NOV. 9 -- Ireland has elected its first woman president, Mary Robinson, a feminist and socialist reformer whose long-shot victory over the candidate of Prime Minister Charles Haughey's entrenched political machine marked one of the biggest political upsets in Irish history.

In a close contest whose results were announced tonight, Robinson defeated Brian Lenihan, a well-known political veteran and one of Haughey's closest allies, by 53 to 47 percent. The presidency is a largely symbolic post.

The campaign was a clash of two distinct political cultures and views about the future of Ireland, which critics contend has Europe's youngest population but one of its most ossified political systems. For decades, the presidency has been the exclusive preserve of Fianna Fail, Haughey's party, a mixture of right, left and center with no distinct ideology beyond the jovial Lenihan's perennial answer to complaints: "no problem."

"My election was on the exact first anniversary of the fall of the Berlin Wall," Robinson told jubilant supporters tonight. "Something has crumbled away in Ireland, too."

A civil-rights lawyer who has long advocated liberalizing Ireland's tough restrictions on divorce, contraception and homosexuality, Robinson, 46, seemed to have no chance of victory when the campaign opened several months ago in a country whose population is 95 percent Catholic. Although a practicing Catholic herself, she is married to a Protestant lawyer -- her parents refused to attend the wedding -- and she has accused the "patriarchal, male-dominated presence of the Catholic Church" of subjugating women in Ireland.

She also has confounded some of her own supporters by expressing sympathy for Protestants in Northern Ireland, and even repudiated the popular Anglo-Irish Accord because she said it did not take into account Protestant fears and objections.

Robinson was the candidate of the small, left-wing Irish Labor Party, running against the popular Lenihan, who was deputy prime minister, for an office that has little budget or constitutional powers beyond the authority to call an election when a prime minister loses a parliamentary vote of confidence.

But Lenihan stumbled into a scandal over whether he had lied about placing a phone call to incumbent president Patrick Hillery eight years earlier. Although the matter was relatively trivial, many voters and commentators saw Lenihan and Haughey's panicked reactions as symptomatic of the dishonesty and corrupt practices that they contend lie at the heart of Irish politics.

A rival government had just fallen in 1982 and Lenihan and his partners wanted the president, an old colleague, to give Haughey a chance to form a new government without holding an election. Hillery resisted the attempt to influence his decision and the matter died until it was revived by Lenihan's opponents in the campaign. Lenihan vehemently denied making the call, but was then confronted with the tape of a recent interview with a university researcher in which Lenihan described the call.

The researcher played the tape for reporters and Lenihan's candidacy plummeted in the polls. Under pressure from a small party in his ruling coalition to fire Lenihan as deputy premier, Haughey at first said the decision was up to "my old friend Brian," but then fired him when Lenihan refused to resign. Haughey's government then narrowly scraped through a confidence vote by 83 to 80, with Lenihan and his sister providing the margin of victory.

While Lenihan was the victim in the presidential contest, Haughey is the real target of Ireland's political reformers. The three-time prime minister is a colorful but controversial figure who carries the nickname "Houdini" for his many escapes from defeat but who operates his party more like a political Godfather, doling out offices and favors to loyalists and settling scores with enemies.

Analysts say he is in trouble now, having lost one of Fianna Fail's most cherished offices. Yet his party's supporters are angered not so much by charges of political malpractice and ineptitude as by the accusation that Haughey failed to stand by an old ally, Lenihan, in the hour of need.

"Haughey should have had the guts to tell the critics to get lost," said Tim Pat Coogan, a prominent author and former newspaper editor. "Instead, he threw his pal to the wolves. Haughey reminds me of Al Pacino in "Scarface" -- he's betrayed all his pals and now he's standing all alone in his mansion making his last stand as the cops break down the door."