While Necho II gained control of the Kingdom of Judah, the combined Assyrian-Egyptian forces failed to defeat the Babylonians, after which Assyria largely ceased to exist as an independent state.
The basic story is told in 2 Kings 23:29–30.
In his days Pharaoh Neco king of Egypt went up to the king of Assyria to the river Euphrates. King Josiah went to meet him; and Pharaoh Neco slew him at Megiddo, when he saw him. And his servants carried him dead in a chariot from Megiddo, and brought him to Jerusalem, and buried him in his own tomb.
There is a longer account recorded later in II Chronicles 35:20–25.
After all this, when Josiah had set the temple in order, Neco king of Egypt came up to make war at Carchemish on the Euphrates, and Josiah went out to engage him. But Neco sent messengers to him, saying, "What have we to do with each other, O King of Judah? I am not coming against you today but against the house with which I am at war, and God has ordered me to hurry. Stop for your own sake from interfering with God who is with me, so that He will not destroy you." However, Josiah would not turn away from him, but disguised himself in order to make war with him; nor did he listen to the words of Neco from the mouth of God, but came to make war on the plain of Megiddo. The archers shot King Josiah, and the king said to his servants, "Take me away, for I am badly wounded." So his servants took him out of the chariot and carried him in the second chariot which he had, and brought him to Jerusalem where he died and was buried in the tombs of his fathers.
The account in Esdras adds some minor details, with the basic difference between it and the earlier account in the Book of Chronicles being that Josiah is described only as being 'weak' at Meggido and asks to be taken back to Jerusalem, where he dies. Cline points out that this brings the story more in line with an earlier prophecy made by the prophetess Huldah (II Kings 22:15–20).
Seven centuries after Josiah's death, Josephus also wrote an account of the events. This contains more details about Josiah's movements on the battlefield which have been suggested come from documents now lost, but Cline suggests it is based on the biblical accounts and perhaps Josephus's own views. (Cline 2000:97)
Finally there is the suggestion that Herodotus records this battle and Egyptian campaign in his writings about the pharaoh Necho, that are included in his famous Histories:
The battle is also discussed in the Talmud where it says that Josiah did not let the Egyptians pass because of a passage in the Bible which says that "A sword shall not pass through your land". (Leviticus 26:6 Taanis 22b)
A view at the topography of the place around the city, will reveal that Megiddo is a small rise among others on a small elevated plateau close to a large level coastal plain large enough to accommodate many thousands of troops. Being that it doesn't dominate the surrounding area, it is not an obvious target, yet it is useful as a garrison and it has a water source from the river Kishon. This explains why Josiah used the terrain to mask his approach as he attempted to ambush the Egyptian army that was on its way to attack the Babylonians in Mesopotamia.
Judah fell under Egyptian control and influence. On his return from Syria and Mesopotamia, Necho II captured and deposed Jehoahaz, the son of Josiah who had just succeeded his father on the throne. The pharaoh enforced a tribute of 100 talents of silver (about 3 3⁄4 tons or about 3.4 metric tons) and a talent of gold (about 34 kilograms (75 lb)) upon the kingdom, and appointed Jehoahaz' older brother Eliakim as king. Necho also changed the name of this new king into Jehoiakim. Jehoahaz was taken captive to Egypt, where he became the first king of Judah to die in exile.
Eric H. Cline explains that there is a division of opinion as to the accuracy of the above account. On the one side are the scholars who believe that it is an accurate report of a surprise attack by Josiah. On the other are those who point out that this would not be the only time the Chronicler 'improved' a story. From being wounded by an arrow to his burial in Jerusalem, the story resembles perhaps too closely stories from I and II Kings about Kings Ahab of Israel and Ahaziah of Judah, events which occurred at least two centuries before Josiah's death. Cline suggests that the Chronicler used details from these stories in Josiah's story.
Cline also suggests the possibility that there may not have been a historical battle of Megiddo involving Josiah, since there's little historical attestation for it outside the Bible. For example, Josiah may have been killed by Necho in some other circumstances.