The countries met in Qatar's capital Doha on Saturday after clashes in border areas between them flared up again since the previous ceasefire expired on Friday.
"During the negotiations, the parties agreed on an immediate ceasefire and the establishment of mechanisms to preserve long-term peace and stability between the two countries," says a representative of Qatar in a statement.
Afghanistan and Pakistan have also agreed to hold follow-up meetings to ensure the ceasefire. The next time the countries are to meet is on October 25 in Istanbul, Turkey.
During the week, several attacks at the border between the countries have claimed over a hundred lives. In connection with this, Pakistan is said to have carried out drone attacks on targets in Afghanistan's capital Kabul. The countries accuse each other of having escalated the situation and of having caused civilian casualties.