First, Oedipus is not a king (a hereditary monarch whose power derives from traditional sources of legitimacy) during most of the play, but a "tyrant", a monarch appointed by the will of the people. He only discovers, ironically, that he is the legitimate king at the end of the play when he loses power.
He arrives as a benefactor to the city, having solved the riddle of the Sphinx. He is determined, at whatever the cost, to find the cause of the ritual pollution that is harming the city. He consults with the people of the city and tries to help them.
His attempt to find the source of pollution reveals that he is that source -- but the curse under which he operates is the will of the gods, and cannot be escaped. That he is a fundamentally good character (albeit flawed) is what makes this a tragedy -- the misfortunes of a bad person are deserved, and thus don't evoke pity.