As a Muslim, if you really feared for yourself and made a statement in order to ward off a potential threat to your life, then you need not worry and it is not counted against you. But if there was no such reason to fear, then you were indeed guilty of a serious offense that needs repentance.
Sheikh Ahmad Kutty, a senior lecturer and Islamic scholar at the Islamic Institute of Toronto, Ontario, Canada, states: If you really feared for your life and made the above statement under duress, then it is not counted against you in Islam. But if there was no such reason to fear, then you were indeed guilty of a serious offense. However, your intention is highly crucial in this matter. If you simply said this in order to ward off a potential but serious threat to your life, then you need not worry; otherwise, you need to repent sincerely to Allah.

Allah says in the Qur’an, (Whoever disbelieves in Allah after he has believed—excepting he who was forced, while his heart remained secure in faith—but those who open their breast to disbelief, upon them shall be anger from Allah, and there awaits them a formidable torment) (An-Nahl 16:106).
the above verse was revealed in the specific context of severe persecutions the early Muslims were subjected to at the hands of their enemies in Makkah. The case of `Ammar and his parents was one of the most obvious instances occasioning the revelation of the above verse. The persecution they suffered was so severe that both his parents, Yasir and Sumayyah, died, thus becoming the first martyrs in Islam. The life of `Ammar, however, was spared since he uttered the words of kufr (disbelief) under extreme duress. When his story was told to the Prophet (peace and blessings be upon him) he said that `Ammar was a true believer whose faith is mixed with his flesh and blood. In other words, it is the intention that counts in such cases. Since he had no intention of renouncing his faith, his words of disbelief in no way detracted from his faith.
In conclusion: You need not be too perturbed over this incident if your heart was firm in your faith while uttering those words. But having said this, however, let me add that should you experience any disquiet in your heart about this action of yours, you should to repent to Allah sincerely and pray that He keeps you steadfast in your faith. Please continue to read the following supplications on a daily basis and ask Allah to grant you steadfastness and strong faith.

Allahumma yaa muqalliba al-quloob thabbit qalbee `alaa deenika. Allahumma yaa muqalliba al-quloob thabbit qalbee `alaa al-haqqi.
allahumma yaa muqalliba al-quloob thabbit qalbee `alaa ta`atika.
(O Allah, You are the twister and turner of hearts; make my heart steadfast in Your religion!
O Allah, You are the twister and turner of hearts; make my heart steadfast in truth!
O Allah, You are the twister and turner of hearts; make my heart steadfast in Your obedience!).

Also, read the following du`aa’, which is known as the master du`aa’ for seeking forgiveness:

Allahumma anta rabbee, laa ilaaha illaa anta. Khalaqtanee wa ana `abduka wa ana `alaa `ahdika wa wa`dika ma istata`tu. A`oodhu bika min sharri maa sana`tu. Aboo’u laka bi ni`matika `alayya, wa aboo’u bi dhanbee; fa ighfir lee, fa innahu laa yaghfiru adh-dhunooba illaa anta.
(O Allah, You are my Lord, there is no god but You. You created me and I am Your servant and I stand by my covenant and pledge with You according to the best of my ability. I seek refuge in You from the evils of my own deeds. I acknowledge Your favors upon me and I confess my sins to You; so forgive me, for You alone can forgive sins.)

May Allah grant us all His grace to live as Muslims and die in faith. Ameen.