LONDON — British Prime Minister Theresa May agreed Monday to a deal with a small and conservative Northern Irish party to prop-up her minority government after more than two weeks of negotiations.

Theresa May, left, greets Arlene Foster, the leader of Northern Ireland's Democratic Unionist Party, at the prime minister's official residence in London on Monday. Carl Court / Getty Images

The U.K. elections on June 8 left May's Conservative Party eight seats short of the 326 needed to form an outright majority government. The result led to weeks of talks between May's party and the Democratic Unionist Party (DUP), which has just ten elected lawmakers — enough to give the Conservatives a slim house majority.

The deal is not without controversy. The DUP — the largest party in Northern Ireland — stands against same-sex marriage and opposes the lifting of a near-total ban on abortion currently in place in Ireland. In contrast, it was the Conservatives who made gay marriage legal in the U.K. in 2014, and abortion has been available on the National Health Service in other parts of the country for decades.

The DUP also has a track record of denying climate change.

Related: What is the Democratic Unionist Party (DUP)?

The agreement comes after a disastrous month for May, whose failed gamble with a snap election backfired. The Conservatives wanted to increase her party’s majority before going into formal Brexit negotiations with the European Union. Prior to the election, the Conservatives held 331 seats and led the left-wing Labour Party by some 20 points in the polls.

But the subsequent result contradicted the polls and saw huge Labour gains and Conservative losses, forcing May into the humiliating situation of being forced to strike deals.

The 1 billion pound ($1.274 billion) agreement is known as a confidence and supply arrangement, meaning that the DUP will vote with the Conservatives on key votes in Parliament.

In addition, the deal comes as the Northern Ireland Assembly is suspended due to rifts in the power-sharing arrangement between the DUP and the opposition Sinn Fein party. A deadline to re-establish power sharing is due at the end of June or the U.K. government may need to step in.

The agreement was vital for May to be able to pass the comprehensive legislation needed over the next two years as the U.K. exits the EU. The DUP supports the U.K.’s exit from the EU, but is against a hard border with its neighbor to the south, the Republic of Ireland.

“In concluding this wide-ranging agreement, we have done so on the basis of advancing the security of our nation, building prosperity for all, and supporting an exit from the European Union that benefits all parts of the United Kingdom,” said DUP leader Arlene Foster on Monday outside the prime minister’s Downing Street residence in London.