Prayer (Kitab Al-Salat)
Dawud :: Book 2 : Hadith 563
Narrated A person from the Ansar:
Sa'id ibn al-Musayyab said: An Ansari was breathing his last. He said: I narrate to you a tradition, and I narrate it with the intention of getting a reward from Allah.
I heard the Apostle of Allah (peace_be_upon_him) say: If any one of you performs ablution and performs it very well, and goes out for prayer, he does not take his right step but Allah records a good work (or blessing) for him, and he does not take his left step but Allah remits one sin from him. Any one of you may reside near the mosque or far from it; if he comes to the mosque and prays in congregation, he will be forgiven (by Allah).
If he comes to the mosque while the people had prayed in part, and the prayer remained in part, and he prays in congregation the part he joined, and completed the part he had missed, he will enjoy similarly (i.e. he will be forgiven). If he comes to the mosque when the people had finished prayer, he will enjoy the same.