The phrase "handwriting (or writing) on the wall" is used to denote a warning that a negative or otherwise disastrous event will soon occur. The fascinating origination of the phrase and its meaning comes from the book of Daniel!
Belshazzar, the son of King Nabonidus, began to co-reign over the Babylonian empire with his father starting in 553 B.C. He decides, in 539, to hold in Babylon a great feast for one thousand of his nobles (Daniel 5:1). No expense is spared in carrying out the lavish banquet!
During the revelry Belshazzar, now drunk from wine, commands that the holy vessels Nebuchadnezzar took from Jerusalem's temple be brought to the festivities. He then proceeds to have himself and his honored guests drink from these gold and silver goblets. The party guests soon begin to use the vessels, in a contemptuous act against God, to celebrate and praise their own pagan deities (Daniel 5:2 - 4)!
The miraculous handwriting
As those at the massive banquet continue to indulge in drunkenness and idolatry, the fingers of a man's hand miraculously appear near one of the hall's walls. The supernatural manifestation then begins writing on a wall the now well-known words, "Mene, Mene, Tekel, Upharsin" (Daniel 5:25).
Belshazzar, while he is witnessing what God's handwriting, becomes terrified. The fear welling up inside of him not only causes his face to turn pale but also his knees to knock together! His now weakened state causes him to fall to the ground (Daniel 5:5 - 6).
Worthless and vain
Pulling himself together, Belshazzar calls for his enchanters and astrologers to interpret the mysterious words. They, of course, prove to be worthless and unable to determine the meaning of the phrase on the wall. Following his wife's suggestion (Daniel 5:10 - 12), the king summons an old man named Daniel (likely in his 90's).
Daniel severely chastises the king for not reeling in his excessive pride and vanity even though he knew Nebuchadnezzar's pride was punished by God (Daniel 4:30 - 34, 5:18 - 23). He then interprets the handwriting on the wall for the king.
A true interpretation
The literal word for word translation of "Mene, Mene, Tekel, Upharsin" in Daniel 5:25 is "numbered" (Strong's #H4484), "numbered," "weighed" (Strong's #H8625) and "divided up or split" (Strong's #H6537).
Daniel elaborates that "mene" means God has numbered his (Belshazzar's) kingdom and will end it. The word "tekel" conveys this judgment was due to the king's character being found morally deficient or wanting. Daniel then uses the word "peres" (Strong's #H6537) instead of "upharsin" to foretell that the empire will not only be divided but also given to the Medes and Persians (Daniel 5:25 - 28).
Belshazzar is killed several hours after seeing the handwriting on the wall when the Persians overrun the city of Babylon (Daniel 5:31). The once great empire receives its final crushing blow when later the same year Persia's Cyrus the Great is victorious at the battle of Opis in Mesopotamia.