Which science fiction story first dealt with the question of a computer program governing society?
Maybe "The Machine Stops" (1909) by E. M. Forster? Although the "machine" isn't really an electronic computer (because they hadn't been invented yet) it does serve the same function as a master computer governing society.
The story, set in a world where humanity lives underground and relies on a giant machine to provide its needs, predicted technologies such as instant messaging and the Internet.
Two decades later than E. M. Forster's "The Machine Stops", this may be a clearer example of a society ruled by a machine.
1930: Paradise and Iron, a novel by Miles J. Breuer, M.D., first published in Amazing Stories Quarterly, Summer 1930, available at the Internet Archive. It is set on a mysterious Caribbean island. Quoting from Everett F. Bleiler's review in Science-Fiction: The Gernsback Years:
The people who watched ineffectually while Davy saved Mildred are all highly cultured, pleasant, sophisticated, beautiful people who live a life of utter ease and perpetual entertainment. The arts are cultivated remarkably, and athletic skill is high. Life seems edenic and beautiful. Everything anyone could want, including luxuries, is available on demand, without money. The only work involved is an occasional day of "supervision." Technology is remarkably high, with automated cars, automated housing, and much else.
Yet there is something very wrong in the City of Beauty. Beneath the insouciant airs and the indolent dawdling there is a note of suppressed panic, a powerful tabu against talking of certain things, and a helpless feeling of inevitability when incidents such as Mildred's "accident" take place.
Davy, who is intelligent, is more and more bewildered as his stay on the island lengthens. He learns that there is no traffic whatever with the outside world (except for Kramer's occasional trips), and that even to mention it is tabu. The people, descendants of gifted, artistic people who settled the island two generations ago when Kramer was young, will not discuss the outside, nor even their own world. He is repeatedly told that the walls have ears.
Davy, after several "accidents" nearly kill him, comes to the conclusion that on the other end of the island, where there is a tabu area called the City of Smoke, there is a ruling caste that has created the reign of psychological terror and that it is responsible for mysterious disappearances, as individuals are seized by machines and raced away to the City of Smoke. He is only partly right, of course.
Let us skip over adventures against individual machines that have evil designs on Davy: Davy penetrates the City of Smoke, which is an incredible assemblage of automated industrialism, and finally learns the truth. Kramer had early developed the concept and technology of automation that finally produced the City of Smoke and by extension the City of Beauty. Involved is an advanced technology that supports invisibly the carefree activities of the City of Beauty. But the machines developed beyond Kramer's intentions and after a time became autonomous, with a gigantic computer (my term) that now rules the island. All the service machinery in the City of Beauty is bugged, visually and aurally, and the machines haul away those who show signs of not accepting the situation. The machine leadership, desiring to understand human emotions, has even taken to vivisecting humans considered rebellious. Davy narrowly escapes such a fate in the City of Smoke.
As Kramer fears, it is only a matter of time before the machines realize that they need not serve the humans at all. Indeed, by the end of the story, the machine rulers have recognized that they are superior to men and have decided to expand beyond the island into the outer world and take it over.