I was really encouraged to see how an Old Testament story that could have easily ended in shame and defeat, instead ended up as triumphant testimony of God’s power and love. Seeking to understand how this happened taught me a few important lessons. 
Israel’s conquest of the promised land under Joshua’s leadership is one of the most exciting accounts in the Bible. One of the most surprising, and potentially devastating, moments of the story — the time when the Israelites’  victory march could have come to a screeching halt — happens when the guileful Gibeonites trick them. They did that to avoid being destroyed along with the rest of the inhabitants of the land, as God had commanded. 
So the men of Israel took some of their provisions, and did not ask for the counsel of the LORD.”
‭‭Joshua‬ ‭9:14‬ ‭NASB1995‬‬ 
This is where all the trouble began: Joshua and the people judged the situation according to their own wisdom, and failed to seek God’s counsel. This was a serious error of presumption, a clear lack of faith, and sin in disobeying God’s command to destroy all of the inhabitants of the land. Which is why it’s especially amazing to see how the story ends:
There was no day like that before it or after it, when the LORD listened to the voice of a man; for the LORD fought for Israel.
‭‭Joshua‬ ‭10:14‬ ‭NASB1995‬‬
The story that starts badly, with Joshua neglecting the Lord, ends triumphantly, with God powerfully responding to Joshua’s request (the sun stood still in the sky!). 
It encouraged me so much to see God listen to the voice of the very one who had neglected to consult Him! And not only that, He was willing to demonstrate His power in accordance with Joshua’s outrageous request. What a blessing to know that even after a terrible failure, it is possible to come boldly to God and ask for help. What I took from this is that God is abundantly willing to demonstrate Himself strong on behalf of the one who has failed. 
We might think that a story that begins with such a sad opening cannot possibly have a happy ending. We need to see that it is not only possible, but also that it is God’s desire, to turn stories that we think should end in shame into stories that exalt His name. 
What Changed the Outcome?
So how did Joshua go from neglecting God’s counsel to securing His power? How was disaster averted — victory snatched from the jaws of defeat — and God ultimately exalted despite Joshua’s failure? There are two moments that spoke to my heart as I re-read the story to try to understand:
First, Joshua Protects the Gibeonites from the Israelites
When the Israelites found out they had been deceived — that the Gibeonites did not actually come from a far off country, but were in fact inhabitants of the land that the Lord had given to them — they were furious! They wanted revenge! ‬‬But Joshua insisted on honoring the oath that they had made with the deceivers “by the name of the Lord” (9:19).
Joshua delivered the Gibeonites from the hands of the sons of Israel, and they did not kill them.
‭‭Joshua‬ ‭9:26‬ ‭
Then, Joshua Protects the Gibeonites from the Canaanites
The men of Gibeon sent word to Joshua to the camp at Gilgal, saying, “Do not abandon your servants; come up to us quickly and save us and help us, for all the kings of the Amorites that live in the hill country have assembled against us.” So Joshua went up from Gilgal, he and all the people of war with him and all the valiant warriors.
‭‭Joshua‬ ‭10:6-7‬ ‭NASB1995‬‬
What I saw in both of these decisions is that Joshua was more passionate that the name of the Lord be honored than that his mistake be covered up. He saw that keeping his oath (even the oath which he had wrongly made!) was a reflection upon His God. His conduct is a great example of the “citizen of Zion” described in Psalm 15: “O LORD, who may abide in Your tent? Who may dwell on Your holy hill? ... He who swears to his own hurt and does not change...” (Psalms‬ ‭15:1, 4‬).
I also saw that he wasn’t so discouraged by his earlier failure that he lost his desire to choose God’s side at the very next opportunity. How easy it is to sin again once we have failed! Yet despite Joshua’s earlier sin, he still had a passion that the name of the Lord not be dishonored further by his conduct. 
Joshua could have seen the attack of the 5 kings as God’s provision, a way of “erasing” their neglect of His counsel. But he did not do that. He reverenced God’s name too much to allow it to be an empty oath (they had sworn to the Gibeonites “by the name of the Lord” (v19)). 
So even when it meant endangering himself and his warriors — defending the very people they were meant to destroy, out of reverence for the reputation of God among a people who were to be destroyed!! — Joshua went against the five kings. 
What a picture of the zeal we ought to have after a failure!
For behold what earnestness this very thing, this godly sorrow, has produced in you: what vindication of yourselves, what indignation, what fear, what longing, what zeal, what avenging of wrong! In everything you demonstrated yourselves to be innocent in the matter.”
‭‭2 Corinthians‬ ‭7:11‬ ‭NASB1995‬‬
We see in Joshua’s defense of the ones who had tricked him a true heart of vindication, indignation, longing, and zeal. I believe that the Lord saw that, too, and honored Joshua’s passion for His name with one of the greatest miracles He ever worked in response to a man’s request. It even says that the Lord killed more of the enemies by hailstones than the Israelites did by sword (Joshua 10:11)!!
Here are the main lessons I took from this story:
  • God is able to work triumph out of defeat 
  • Never accept one sin as the reason to commit another
  • Never hang my head in shame after a sin — as that gives the enemy a foothold — but renew my resolve to conduct myself as a child of God from this point forward
  • Come boldly to the Lord for help, even after I have sinned, confident that He is more interested in His name being honored than I am
Praise the Lord for His mercy. What a mighty God we serve!