Mr Hun Sen, opposition leader Sam Rainsy and others met for five hours behind closed doors in the third round of talks since lawmakers from Mr Rainsy's Cambodia National Rescue Party boycotted their seats in the parliament since July 28 election last year. The opposition alleged the polls were rigged, and demanded reforms and new elections.
"It was a success. Now you can applaud," said Mr Hun Sen, who was seen smiling when walking out of the meeting room.
Rainsy said the two leaders must seek an audience with King Narodom Sihamoni to inform the monarch about the agreement before the 55 MP-elects from his party swear in and join the meeting of the National Assembly.
"We have no choice. There is only suitable choice is to end the political crisis, to end the standoff." Mr Rainsy told reporters.
A joint statement said the parties agreed to work together at the National Assembly in order to solve important issues and to reform some institutions.
"Both parties agreed to do a reforming and strengthening of some major state institutions especially independent institutions that could serve the benefit of the nation, the people and comply with pluralism democracy," they said in the statement.
Both parties also said they agreed to change the dates of upcoming elections but did not say when. The next general election is now scheduled in July 2018.
Tuesday's talks came after last week's arrest of seven opposition lawmakers and another party activist after violence broke out when party members tried to stage a rally at Freedom Park in Phnom Penh. It was expected they will be released after the agreement.
Mr Hun Sen has been in power for almost three decades and, despite Cambodia being formally democratic, his government is authoritarian and known for intimidating opponents. A strong showing by Mr Rainsy's party in last year's polls posed the strongest challenge to Mr Hun Sen in years.