Word of an impending attack on Judah by the Moabites and Ammonites caused Jehoshaphat to call for nation-wide fasting and penance. A multitude assembled at the temple in Jerusalem, where Jehoshaphat gave a pathos-laden prayer begging God to forgive them all because they were all so very sorry for whatever they had done to offend It. Then a dude named Jahaziel was possessed by God to tell everyone that God was pleased with them and that if they went out to battle, they would win without even striking a blow.
So next day the army marched out to find that faction had caused their allied enemies to fight amongst themselves. Many were dead, the rest scattered, so the Judaeans pillaged what remained and them went back home rejoicing.
However, God became angry with Jehoshaphat when he allied with King Ahaziah of Israel to build a fleet of ships and caused them all to wreck.