The Prophet ﷺ said, "When the appointed time of death for one of you is to come in a certain land, a need will arise that drives him to that very place. When he reaches the furthest point of his journey, Allah, glorified be He, takes his soul. Then on the Day of Resurrection, the earth will say, 'My Lord, this is what You entrusted to me.'"
عن النبي ﷺ قال: إذا كان أجل أحدكم بأرض أوثبته إليها الحاجة، فإذا بلغ أقصى أثره قبضه الله سبحانه، فتقول الأرض يوم القيامة: رب هذا ما استودعتني.
Ibn Majah (4263) and Hakim (1/41) both narrated it through routes from Umar bin Ali, who said, "Ismail bin Abu Khalid informed me, from Qays bin Abu Hazim, from Abdullah bin Masud," and he related it. The wording given is that of Ibn Majah. Its isnad is sahih, and the discussion of it is given in detail in the chapter on funerals.