Britain and Ireland signed a historic agreement today giving Dublin an official voice in governing the troubled British province of Northern Ireland for the first time since the island's partition 64 years ago.

The prime ministers of the two countries, Margaret Thatcher of Britain and Garret FitzGerald of Ireland, met under heavy security this afternoon at an 18th Century castle outside Belfast to sign the accord, which followed more than a year of secret talks between their governments.

The agreement establishes a permanent joint secretariat in Belfast, and an Intergovernmental Conference in which senior British and Irish officials will meet regularly to discuss internal Northern Irish affairs, including security, political institutions and the judiciary in Ulster, as the province is known historically.

Designed to protect the interests of the province's Catholics, the agreement represents a major initial effort to end the currrent 16-year-old round of sectarian violence in the North between the majority Protestant and minority Catholic communities, whose grievances go back centuries.

In return for this role in the North, Dublin has formally recognized British sovereignty over the six northern counties that its own constitution declares belong to Ireland. Dublin also has committed itself to support the British policy of working toward "devolved" government, or home rule, in the province, under which the Protestant and the Catholic communities would find a way to share authority under a system respecting their different "traditions."

Ultimately, home rule would replace direct control from London and the need for the joint conference agreed on today.

In a news conference after the signing, both leaders appealed for international support. Asked about rumors of a U.S. aid program in Ulster to help bolster the agreement, Thatcher said such assistance "would of course be welcomed."

In Washington, President Reagan and House Speaker Thomas P. O'Neill lauded the pact in a joint White House appearance. The president indirectly referred to the prospect of aid when he said that "we hope that in a bipartisan way we can go forward with anything we can do to help . . . in restoring sound economics there . . . "

Dissent came in London, where a junior British treasury minister, Ian Gow, resigned to protest the new Irish role in the North, and in Dublin, where the republic's opposition leader, Charles Haughey, called it "a very severe blow . . . to the concept of Irish unity."

As expected, Protestant political leaders immediately denounced the agreement as British "treachery" and a betrayal of their rights of full citizenship in the United Kingdom. Democratic Unionist Party leader Ian Paisley, saying he was speaking on behalf of all his coreligionists, who make up two-thirds of Ulster's 1.5 million people, declared that the agreement would be "destroyed."

Standing outside the doors of Hillsborough Castle as Thatcher and FitzGerald met inside, Paisley said, "This is not the time for words; this the time for action." A crowd of about 100 Unionists, as those who favor continued union with Britain are called, gathered inside the small castle town before it was sealed off by police early this morning to cheer the hard-line Unionist leader, who played a key role in scuttling the last major initiative in the province in 1974, and set an Irish flag on fire.

Although for weeks Paisley and the Official Unionist Party of James Molyneaux have issued thinly veiled threats of violence if the agreement allowed any Irish voice in Ulster, they called today for initial calm and said they would try legal and legislative means to negate the accord. The two predominantly Protestant parties have called a special strategy meeting for Saturday.

On the Catholic, or Nationalist side, so known because of its sympathy for reuniting the divided parts of the island, John Hume, leader of the moderate Social Democratic and Labor Party (SDLP), cautiously supported the agreement, saying it represented "an opportunity to make progress."

But Sinn Fein, the legal political arm of the outlawed Provisional wing of the Irish Republican Army (IRA), denounced it as "propaganda," and said it would continue to advocate attacks against British rule here.

The IRA claimed responsibility for a land mine that exploded this morning outside the town of Armagh, killing one policeman and severely wounding another. A total of 221 police of the Royal Ulster Constabulary have died since the current round of "troubles" began here in 1969. Altogether, 2,500 people have died in the violence.

In their news conference, Thatcher and FitzGerald asked members of both Northern Ireland communities to give the agreement a chance.

"To Nationalist and Unionist alike I appeal," FitzGerald said. "Look at and evaluate this agreement not as some people in both communities who are committed to maintaining division and hatred will attempt to portray it but for what it is."

Thatcher said she wanted it to "offer hope to young people" in the province. "We entered into this agreement," she said, "to defeat the men of violence and to bring peace and stability . . . . we shall do everything to make it succeed . . . . Whether it succeeds will depend also on the will of the people, and I hope they will seize the chance."

Thatcher and FitzGerald clearly sought to reassure their respective constituencies today that their interests were favored.

Thatcher stressed that the accord provided for "no change in the status of Northern Ireland without its consent." She reminded Unionists that "the legitimacy of the Unionist position" inside the United Kingdom now "has been recognized by the republic of Ireland in a formal, international agreement."

She insisted that it brought no lessening of British sovereignty. The accord makes clear, Thatcher said, that Britain and Ireland "will strive to resolve differences" over managing Northern Ireland, "but in the last resort the responsibilities and decisions for the administration of affairs north of the border remain with the United Kingdom."

Thatcher said Unionists should welcome the plan as a way to stop violence, both by increasing the Catholic stake in peace and thereby lessening support for the IRA, and by committing the Irish government to more cooperation in hunting down northern terrorists who take refuge in the south.

FitzGerald made much of new opportunities for Nationalists in the accord, and the creation of conditions in which Catholics will have a greater voice in Northern Irish institutions and protection against political and economic discrimination.

Both leaders said their respective parliaments would be asked to approve the agreement, and implementation is hoped for within the next several weeks.

The first meeting of the Intergovernmental Conference, with British Northern Ireland Secretary Tom King and Irish Foreign Minister Peter Barry, will discuss security in the province.