For centuries, English translations of the ancient Greek historian Herodotus have retold his story of Solon (the famous lawgiver of the Athenians) and Crœsus (a highly cultured and fabulously wealthy king of Lydia who also happened to be very successful in war). The story ends with a moral (and a proverbial saying) that seems similar in import to the one that Yoichi Oishi cites in his question.
After having established his laws in Athens, Solon traveled through various parts of Asia Minor and eventually met King Crœsus in his capital at Sardis. Crœsus showed him his various treasures and thought to dazzle him with his wealth, but Solon seemed unimpressed. And when Crœsus asked Solon who (in Solon's opinion) was the most truly happy person he had met with in his travels, Solon identified first a citizen of Athens who had served his city well, raised well-esteemed children, lived to see his grandchildren, watched his country flourish, and died fighting in its defense; and second, two brothers who had loved each other and done a remarkable deed to honor their mother (a priestess), and who died peacefully in their sleep at the height of their acclaim.
Crœsus then asked why Solon didn't list his host as among the happiest of men, and Solon told him that it was much too early to form any such judgment about him:
"Therefore, in our opinion," continued he, "no man can be esteemed happy, but he whose happiness God continues to the end of his life[.]"
Years later, the Medes under Cyrus defeated the Lydian army and captured Crœsus, who was condemned to be burned alive—and here we pick up the story as recounted by Charles Rollin in The Ancient History of the Egyptians, Assyrians, Babylonians, Lydians, Persians and Medes (1832):
Accordingly, the funeral pile was prepared, and that unhappy prince being laid thereon, and just upon the point of execution, recollecting the conversation he had formerly had with Solon, was woefully convinced of the truth of that philosopher's admonition, and in remembrance thereof, cried aloud three times, "Solon! Solon! Solon!" Cyrus, who, with the chief officers of his court was present at this spectacle, was curious to know why Crœsus pronounced that celebrated philosopher's name with so much vehemence in this extremity. Being told the reason, and reflecting upon the uncertain state of all sublunary things, he was touched with commiseration at the prince's misfortune, caused him to be taken from the pile, and treated him afterwards, as long as he lived, with honour and respect. Thus had Solon the glory, with one single word, to save the life of one king, and give a wholesome lesson of instruction to another.
Solon's advice to Crœsus has been summarized in various ways. According to Martin Manser, The Facts on File Dictionary of Proverbs, second edition (2007), Solon's wording was "Call no man happy before he dies, he is at best fortunate," and Sophocles expressed the same idea as "Deem no man happy until he passes the end of his life without suffering grief." Manser gives the proverb as
call no man happy till he dies