A ceasefire between Thailand and Cambodia has come into effect along the border, where almost three weeks of deadly clashes have forced nearly one million people from their homes.

In a joint statement, the defence ministers of the two countries agreed to freeze the front lines where they are now, ban reinforcements and allow civilians living in border areas to return as soon as possible.

The ceasefire took effect at noon local time (05:00 GMT) on Saturday. Once it has been in place for 72 hours, 18 Cambodian soldiers held by Thailand since July will be released, the statement said.

The breakthrough came after days of talks between the two countries, with diplomatic encouragement from China and the US.

The agreement prioritises getting the displaced back to their homes, and also includes an agreement to remove landmines.

Thailand's Defence Minister Natthaphon Narkphanit described the ceasefire as a test for the other party's sincerity.

Should the ceasefire fail to materialise or be violated, Thailand retains its legitimate right to self-defence under international law, he told reporters.

UN human rights chief Volker Türk said he hopes the ceasefire will pave the way for peace, while an EU spokesperson urged good faith in its implementation.

Thailand had been reluctant to accept the ceasefire, saying the last one was not properly implemented. They also resented what they saw as Cambodia's efforts to internationalise the conflict.

Unlike the last ceasefire in July, US President Donald Trump was conspicuously absent from this one, although the US State Department was involved.

That ceasefire agreement collapsed earlier this month when fresh clashes erupted; both sides blamed each other for the breakdown.

The Thai army stated its troops had responded to Cambodian fire in Thailand's Si Sa Ket province, injuring two Thai soldiers. Meanwhile, Cambodia's defence ministry accused Thai forces of launching the first attack.

Disagreement over the border goes back more than a century but tensions escalated earlier this year following a group of Cambodian women singing patriotic songs in a disputed temple. Following extensive fighting in July, which caused significant casualties, a fragile ceasefire was negotiated but quickly collapsed.