Venezuela and Guatemala - both vying for the Latin American non-permanent seat on the UN Security Council - have agreed to withdraw their bids.
UN rules allow for voting to continue until agreement is reached
The move opens the way for Panama to take the non-permanent seat.
Nearly 50 rounds of voting failed to resolve the contest between Guatemala and Venezuela.
The United States had opposed Venezuela's candidacy because of its deteriorating relationship with President Hugo Chavez.
Now Guatemala and Venezuela are expected to formally endorse Panama at a meeting of the Latin American group of countries at the UN later on Thursday.
The agreement is a significant political and personal setback for President Chavez, who had spent the past eight months travelling the world trying to gain the necessary votes for his country's UN bid, the BBC's Greg Morsbach in Caracas says.
Mr Chavez's decision to back down marks a U-turn from his tough stance two weeks ago when he promised that Venezuela would never surrender or negotiate on the issue, our correspondent says.
Diplomats agree that Mr Chavez's now infamous speech to the UN General Assembly in September, during which he compared President George W Bush to the devil, damaged his country's standing.
The announcement about the deal was made after talks between the foreign ministers of Guatemala and Venezuela.
"The two foreign ministers have agreed on two issues," said Ecuador's UN ambassador Diego Cordovez, who was a mediator during the talks.
Five permanent members
Ten elected to serve two-year terms
Each year five elected members change, within regional blocs
Arab state always represented in Africa or Asia bloc
"Both will withdraw their candidacy to the Security Council, and second, Panama will be the country that the three of us will present to the [Latin American] group" to represent the region, Mr Cordovez said.
Asked why Panama had been chosen as a compromise candidate, Guatemalan Foreign Minister Gert Rosenthal said: "It's a country that unites South America and Central America."
"We're concerned about the idea of divisions between the north and the south of Latin America. We would like to put that idea to rest by seeking a country that is well received at both extremes of our continent," he said.
Venezuelan Foreign Minister Nicolas Maduro said his country was "happy to reach this consensus".
"We are recognising today this role of Panama as a political and geographical meeting point," he said.
The UN General Assembly held 47 rounds to choose between Guatemala and Venezuela.
CURRENT ELECTED MEMBERS
(Replaced from 2007 by country in brackets)
Tanzania (South Africa)
*To be formalised
Guatemala gathered more support in nearly all the rounds, but neither side was able to achieve the two-thirds majority needed in the 192-member General Assembly.
UN rules allow for voting to continue indefinitely until agreement is reached.
A 1979 battle between Cuba and Colombia took three months of voting to resolve, with Mexico eventually emerging as the compromise candidate.
Five of the 15 UN Security Council seats are held permanently by China, the US, Russia, the UK and France.
The others are held by regional blocs from Africa, Latin America, Asia, Western Europe and Eastern Europe.
Other regional seats, which are rotated every two years, went to Indonesia, South Africa, Italy and Belgium in the first round of voting last month.