Harsanyi was born on May 29, 1920 in Budapest, Hungary, the son of Alice (Gombos) and Charles Harsanyi, a pharmacy owner. His parents converted from Judaism to Catholicism a year before he was born. He attended high school at the Lutheran Gymnasium in Budapest. In high school, he became one of the best Problem solvers of the KöMaL, the Mathematical and Physical Monthly for Secondary Schools. Founded in 1893, this periodical is generally credited with a large share of Hungarian students' success in mathematics. He also won the first prize in the Eötvös mathematics competition for high school students.
Although he wanted to study mathematics and philosophy, his father sent him to France in 1939 to enroll in chemical engineering at the University of Lyon. However, because of the start of World War II, Harsanyi returned to Hungary to study pharmacology at the University of Budapest (today: Eötvös Loránd University), earning a diploma in 1944. As a pharmacology student, Harsanyi escaped conscription into the Hungarian Army which, as a person of Jewish descent, would have meant forced labor.
However, in 1944 (after the fall of the Horthy regime and the seizure of power by the Arrow Cross Party) his military deferment was cancelled and he was compelled to join a forced labor unit on the Eastern Front. After seven months of forced labor, when the German authorities decided to deport his unit to a concentration camp in Austria, John Harsanyi managed to escape and found sanctuary for the rest of the war in a Jesuit house.
After the end of the war, Harsanyi returned to the University of Budapest for graduate studies in philosophy and sociology, earning his Ph.D. in both subjects in 1947. Then a devout Catholic, he simultaneously studied theology, also joining lay ranks of the Dominican Order. He later abandoned Catholicism, becoming an atheist for the rest of his life. Harsanyi spent the academic year 1947–1948 on the faculty of the Institute of Sociology of the University of Budapest, where he met Anne Klauber, his Future wife. He was forced to resign the faculty because of openly expressing his anti-Marxist opinions, while Anne faced increasing peer pressure to leave him for the same reason.
The two did not marry until they arrived in Australia because Klauber's immigration papers would need to be changed to reflect her married name. The two arrived with her parents on December 30, 1950, and they looked to marry immediately. Harsanyi and Klauber were married on January 2, 1951. Neither spoke much English and understood little of what they were told to say to each other. Harsanyi later explained to his new wife that she had promised to cook better food than she usually did.
Harsanyi's Hungarian degrees were not recognized in Australia, but they earned him credit at the University of Sydney for a master's degree. Harsanyi worked in a factory during the day and studied economics in the evening at the University of Sydney, finishing with a M.A. in 1953. While studying in Sydney, he started publishing research papers in economic journals, including the Journal of Political Economy and the Review of Economic Studies. The degree allowed him to take a teaching position in 1954 at the University of Queensland in Brisbane. While in Brisbane, Harsanyi's wife became a fashion designer for a small factory.
In 1956, Harsanyi received a Rockefeller scholarship that enabled him and Anne to spend the next two years in the United States, at Stanford University and, for a semester, at the Cowles Foundation. At Stanford Harsanyi wrote a dissertation in game theory under the supervision of Kenneth Arrow, earning a second PhD in economics in 1959, while Anne earned an MA in psychology. Harsanyi's student visa expired in 1958 and the two returned to Australia.
After working for a short time as a researcher at the Australian National University in Canberra, Harsanyi became frustrated with the lack of interest in game theory in Australia. With the help of Kenneth Arrow and James Tobin, he was able to move to the United States, taking a position as professor of economics at the Wayne State University in Detroit between 1961 and 1963. In 1964, he moved to Berkeley, California; he remained at the University of California, Berkeley until retiring in 1990. Shortly after arriving in Berkeley, he and Anne had a child, Tom. While teaching at Berkeley, Harsanyi did extensive research in game theory. From 1966 to 1968, Harsanyi was part of a team of game theorists tasked with advising the United States Arms Control and Disarmament Agency in collaboration with Mathematica, a consulting group from Princeton University led by Harold Kuhn and Oskar Morgenstern.
He is best known for his contributions to the study of game theory and its application to economics, specifically for his developing the highly innovative analysis of games of incomplete information, so-called Bayesian games. He also made important contributions to the use of game theory and economic reasoning in political and moral philosophy (specifically utilitarian ethics) as well as contributing to the study of equilibrium selection. For his work, he was a co-recipient along with John Nash and Reinhard Selten of the 1994 Nobel Memorial Prize in Economic Sciences. According to György Marx he was one of The Martians.
John Harsanyi died on August 9, 2000, from a heart attack in Berkeley, California, after he suffered from Alzheimer's disease.