LONDON — She wore bright green; he was somber-suited. Between them lay a gulf of history that had been beyond bridging, defined by faith and nation, hatred and loss, war and, only more recently, redemption.

Yet, in what generations on both sides had been raised to see as the most improbable of encounters, Queen Elizabeth II, Britain’s head of state, shook hands on Wednesday with Martin McGuinness, a onetime commander of the Irish Republican Army. It was hard to guess what secret thoughts they harbored behind smiles for the cameras that seemed as warm as they were ultimately inscrutable.

The setting alone, in Belfast, Northern Ireland, evoked three decades of sectarian strife that drew in the British forces, of which the queen is the nominal commander in chief, in a fight with I.R.A. guerrillas seeking a united Ireland before the Good Friday peace agreement of 1998.

The Troubles, as the turbulent, tangled conflict was known, claimed about 3,500 lives, 60 percent of them in I.R.A. shootings and bombings, and scarred the souls of Northern Ireland’s competing citizenries. John Reid, Britain’s minister in charge of Northern Ireland in 2001 and 2002, described the encounter on Wednesday as “huge” and called it “the ultimate handshake.”

Appropriately, for a historic moment in an era of 24-hour news and instant communication, the handshake had something of a closely choreographed minuet to it.

A first private handshake took place without the cameras present. What was said at that moment is not known. When the cameras were present, Mr. McGuinness, now deputy first minister in the power-sharing government, was just one of five besuited men in a reception line waiting to shake the gloved hand of the queen.

Mr. McGuinness seemed to incline his head to the monarch who once stood for everything he opposed. He spoke quietly to the queen in Irish, his words translating as “goodbye and godspeed,” to conclude their brief encounter.

She smiled but did not reply, maintaining the customary reserve that underpins her mystique. So onlookers were left to ponder whether she thought at that moment of her cousin, Earl Mountbatten, killed by an I.R.A. bomb aboard a yacht off western Ireland in 1979, or whether Mr. McGuinness thought of the days he fought against her soldiers.

Mr. McGuinness has said he left the I.R.A. in 1974 to embrace the electoral policies of Sinn Fein, its political wing. But according to some British intelligence officials, he remained a top commander into the 1990s.

For both figures — monarch and politician — the encounter was fraught with risks: criticism for the queen for shaking the hand of a man once labeled a terrorist, and castigation for Mr. McGuinness for betraying the sacred cause of a united Ireland.

“Because this involves Martin meeting the British monarch,” Gerry Adams, the Sinn Fein president, said before Wednesday’s meeting, “this will cause difficulty for republicans and nationalists who have suffered at the hands of British forces in Ireland over many decades.”

An error has occurred. Please try again later.

You are already subscribed to this email.

For all its qualifications, the meeting symbolized a new, if still uncertain, era. The days of open warfare are gone. The former combatants — the predominantly Roman Catholic republicans, like Mr. McGuinness, and the mainly Protestant unionists seeking close ties with mainland Britain — now sit together in a power-sharing government.

Not only that, the queen, 86 years old and this year celebrating her Diamond Jubilee after six decades on the throne, has become an emblem of a broader reconciliation across the Irish Sea, traveling last year to Dublin for the first visit by a reigning British monarch to the Irish Republic.

That voyage, too, would have once seemed improbable in a land that reviled the British monarchy for centuries and fought a bloody war of independence leading to the creation of the Irish Free State on territory that excluded Northern Ireland.

The queen’s overture to Mr. McGuinness, the columnist Simon Jenkins wrote in The Guardian, “is across a political divide but also a religious one, the divide that created Irish partition in 1922 and has underlain Ulster’s troubled history ever since.”

“For a monarch to cross a divide is not to unite it, but it is better than not crossing at all,” Mr. Jenkins wrote.

In recognition of the specters that still haunt Northern Ireland, the queen seemed scripted to tread cautiously, paying homage to both sides.

She arrived in Northern Ireland on Tuesday and visited Enniskillen, a town where an I.R.A. bomb killed 11 people in 1987. Queen Elizabeth, the titular head of the Church of England, also took time to visit a Roman Catholic Church.

Later on Tuesday, in Belfast itself, the police fought running battles with youths throwing gasoline bombs in Broadway, a republican area, in a scene that recalled lingering hostilities and continued divisions in a city carved into sectarian zones by barriers and so-called peace walls between neighborhoods.

“Far from being reconciled,” Mr. Jenkins wrote in The Guardian, “most of Belfast has merely been segregated.”

As a constitutional monarch in a land that has no written constitution, the queen has no formal political power, but her imprimatur on a process of Anglo-Irish reconciliation is seen as exerting a powerful influence across Ireland — a phenomenon that some in her family rank among her greatest achievements, beyond simply keeping the monarchy afloat after the death of Diana, Princess of Wales, in 1997.

At that time, public faith in the queen and her family dipped alarmingly. The monarch was cast as aloof and uncaring, the family dysfunctional. Since then she has studiously rebuilt her personal stature, so much so that in recent surveys, almost 70 percent said they believed the monarchy was good for the country and only a fifth wanted its abolition.

In a television documentary broadcast recently, Prince Charles, her eldest son and heir to the throne, mused on the transformation since the death of Lord Mountbatten. “Who would have guessed then that things would have changed so much?” he said. “The fact that the queen managed to go to Ireland on a state visit is a remarkable thing in itself. And, in many ways, I think that’s her greatest achievement.”

Correction: June 27, 2012

The picture caption with an earlier version of this article misidentified the government in which Martin McGuinness is deputy first minister. He serves that role for the Northern Ireland provincial government, not Ireland’s government.

Douglas Dalby contributed reporting from Belfast, Northern Ireland.

A version of this article appears in print on June 28, 2012, on Page A4 of the New York edition with the headline: Clasping Hands, Ex-Guerrilla and Queen Briefly Bridge a Divide. Order Reprints|Today's Paper|Subscribe