Ahaziah’s downfall came from God, through that visit to Joram: when he arrived, he rode out with Joram against Jehu son of Nimshi, whom Yahweh had anointed to cut off the house of Ahab.
In context
5It was on their advice that he went with Joram son of Ahab king of Israel to fight Hazael king of Aram at Ramoth-gilead; and the men of Ramah wounded Joram. 6He went back to Jezreel to recover from the wounds they had dealt him at Ramah when he fought Hazael king of Aram. And Azariah son of Jehoram king of Judah went down to Jezreel to visit Joram son of Ahab, because he was ill. 7Ahaziah’s downfall came from God, through that visit to Joram: when he arrived, he rode out with Joram against Jehu son of Nimshi, whom Yahweh had anointed to cut off the house of Ahab. 8While Jehu was carrying out judgment on the house of Ahab, he came upon the officers of Judah and the sons of Ahaziah’s brothers, who were in Ahaziah’s service, and he killed them. 9Then he hunted for Ahaziah, and they seized him while he was hiding in Samaria and brought him to Jehu, who put him to death. They buried him, for they said, “He is a son of Jehoshaphat, who sought Yahweh with all his heart.” And the house of Ahaziah had no one left with strength enough to hold the kingdom.