As in the case of most successful people, Daniel's colleagues envied him. They schemed to trap and destroy him. The Book of Daniel chapter 6 tells us that they forced the king to order that those who pray to anyone other than the king will be destroyed. Daniel’s enemies knew that being a devout Jew, he will not comply and that will lead to his death.
Daniel was a person of integrity. He ignored the royal edict and continued with his routine of prayer to his God, Yahweh. His enemies caught him in action. They reported the matter duly to the king.
Though the king was reluctant to act against Daniel, they forced the king to act on his own order. Though reluctant, the king ordered that Daniel be thrown into the den of hungry lions. We know the rest of the story well. The lions did not attack Daniel. God had shut their mouths.
The king spent the night sleepless. At the wee hours of the morning, he rushed to the den of the lions to find out what has happened to Daniel. He finds that Daniel is safe and the lions haven’t even scratched him. At the king’s orders they soldiers pulled Daniel out and his opponents and their entire families were thrown into the same den. The hungry lions tore them apart.
What is important in this story is the song that king Darius sang when Daniel was pulled out of the den of lions (Daniel 6:26-28). The king reverses the earlier order that the people should fear and tremble before the God of Daniel instead of the king.
The story ends not with the rescue of Daniel from the pit, but king Darius proclaiming the glory of Daniel’s God and ordering his nation to fear that God. The book of Daniel tells us that the king sang a song of praise to the God of Daniel.
Things would have been very different if Daniel had given in to the order of the king in order to save his skin. His integrity not only saved his life but led to the greater glory of God before a pagan king and his empire. His prayer to God was private. But he did it ignoring the dire consequence of his action of defying a power lesser than the power of his God. God protected him from the consequence that his opponents had designed for him. He also used that to bring glory to his name in all the empire of Persia.