Answer: Allah Subhanahu wa Ta'ala answered this question for us in the Qur'an. He said:
إِنَّ الدِّينَ عِندَ اللَّهِ الْإِسْلَامُ
The only religion that is acceptable to Allah is Islam. (Aali 'Imran 19)
And Allah said:
وَمَن يَبْتَغِ غَيْرَ الْإِسْلَامِ دِينًا فَلَن يُقْبَلَ مِنْهُ وَهُوَ فِي الْآخِرَةِ مِنَ الْخَاسِرِينَ
And whoever desires other than Islam as a religion, it will never be accepted from him, and in the Hereafter, he will be among the losers. (Aali 'Imran 85)
Likewise, Allah said:
وَلَقَدْ أُوحِيَ إِلَيْكَ وَإِلَى الَّذِينَ مِن قَبْلِكَ لَئِنْ أَشْرَكْتَ لَيَحْبَطَنَّ عَمَلُكَ وَلَتَكُونَنَّ مِنَ الْخَاسِرِينَ
And it was already revealed to you and to those before you that if you should associate [anything] with Allah, your work would surely become worthless, and you would surely be among the losers. (Az-Zumar 65)
These ayat, and many others like them, show that without the religion of Islam, none of our deeds can be accepted.
If Allah said this about the Prophet Muhammad ﷺ, then in Surah Al-An'am, Allah said the same about 18 prophets. He mentioned:
وَلَوْ أَشْرَكُوا۟ لَحَبِطَ عَنْهُم مَّا كَانُوا۟ يَعْمَلُونَ
But if they had associated others with Allāh, then worthless for them would be whatever they were doing. (Al-An'am 88)
This tells us that without the religion, good character does not count for anything.
Our mother, 'Aisha رضي الله عنها, reported:
قُلْتُ يَا رَسُولَ اللَّهِ ابْنُ جُدْعَانَ كَانَ فِي الْجَاهِلِيَّةِ يَصِلُ الرَّحِمَ وَيُطْعِمُ الْمِسْكِينَ فَهَلْ ذَاكَ نَافِعُهُ قَالَ صَلَّى اللهُ عَلَيْهِ وَسَلَّمَ لَا يَنْفَعُهُ إِنَّهُ لَمْ يَقُلْ يَوْمًا رَبِّ اغْفِرْ لِي خَطِيئَتِي يَوْمَ الدِّينِ
I said, “O Messenger of Allah, the son of Jud’an would maintain family ties and feed the poor in the time of ignorance. Will it benefit him?” The Prophet, peace and blessings be upon him, said, “It will not benefit him, for he never said even for one day: My Lord, forgive my sins on the Day of Judgment.” (Sahih Muslim 214)
This clearly shows that without religion, there can be no benefit to good character.
And Allah knows best.
— Answered by Ustadh Muhammad Tim Humble