Most of the 'Ulama' believe that Allah is the Sublime Companion (Ar-Rafiq Al-A'la). Ar-Rafiq (the Companion) is one of the Divine Names. Some take it to mean the supreme communion of angels, Prophets, martyrs and the righteous. Prophet Yusuf (Joseph) had prayed to Allah, "... And join me with the righteous." (12:101).
At the hour of death, man should cut off his link with the world and unite it with the Hereafter. By seeking Divine forgiveness, the Prophet (PBUH) aimed at moral elevation and abundance of goodness. Otherwise, he was protected by Allah and immune against sinning.