Irish poet and human rights activist Michael D. Higgins was officially confirmed as his country's ninth president on Saturday after winning nearly 57 percent of the vote in the final count.
The 70-year-old former culture minister for the Labour party, the junior partner in the coalition government in Dublin, staged a remarkable comeback to beat an ex-IRA commander and a reality TV star.
He will succeed Mary McAleese, who spent two seven-year terms in the ceremonial post, and now faces the task of representing Ireland abroad as it struggles to rebuild its shattered economy.
At the Dublin Castle count centre, returning officer Riona Ni Fhlanghaile declared Higgins the winner after he accumulated 1,007,104 votes out the total 1,771,762 cast in Thursday's election after four counts.
Overall voter turnout was 56 percent.
"As he has reached the quota I hereby declare Michael D. Higgins elected to the office of president of Ireland," Ni Fhlanghaile said.
Under Ireland's complicated election system with voting for second and third preference candidates, the winner needed at least 885,882 votes, which represents 50 percent of the valid votes plus one.
Higgins achieved 56.8 percent of the vote in the final count, but only 39.6 percent of the first-preference votes.
"I will be a president for all the people," Higgins said in his victory speech, adding that during the election campaign he had felt the pain of the Irish people during the country's economic crisis.
"I recognise the righteous anger but I also saw the need for healing and to move past recrimination," said the diminutive Higgins.
Belfast-born McAleese congratulated Higgins, saying his success "marks the start of an exciting chapter for our country, our global Irish family and for the Higgins family".
Irish Prime Minister Enda Kenny said Higgins would be an "outstanding president and personality over the next seven years".
Higgins beat a record field of eclectic candidates that also included the first openly gay man to run for the presidency, and a former Eurovision song contest winner.
The official result on Saturday confirmed what had been clear from Friday afternoon when Higgins's main rival, independent businessman Sean Gallagher, conceded.
The victory represents a remarkable turnaround for Higgins, who was trailing about 15 points behind before the shaven-headed Gallagher's campaign exploded in the final days of the presidential contest.
During a stormy televised debate on Monday, Sinn Fein candidate and former IRA commander Martin McGuinness accused Gallagher of collecting a 5,000-euro ($7,000) donation from a convicted criminal -- and his lead melted away.
A poll showed 28 percent of voters changed their minds in the final week of the campaign, with 58 percent of them switching from Gallagher, who featured in the reality TV show "Dragons' Den", to Higgins.
McGuinness, who is deputy first minister of British-ruled Northern Ireland and was running on a ticket of unity for the island, has also sent his congratulations to Higgins.
Married with three sons and a daughter, Higgins is a fluent Irish speaker, president of the soccer club in his Galway base in the west of Ireland and has had three books of poems published.
He recited his poetry on a live album by Irish rock band, The Stunning, and was a columnist for Irish music magazine Hot Press.
He has campaigned for justice and peace and humanitarian issues in Latin America, Somalia and Iraq and has won international peace prizes.
When he was arts minister in the 1990s he boosted the country's film industry, established an Irish language TV station and set up arts centres and theatres around the country.