The construction is "etwas (Nom) gefällt jemandem (Dat)". So the person who likes something is in the dative case, while the thing that is liked is in the nominative case. *
*This is different from English "like", where the person is the subject, and the thing the object. You'll often have expressions that have similar meaning in two languages, but construct very differently.
In your sentence, "ihm" is already the dative object and refers to the person. The pronoun replacing the subject of this subordinate cause must be in the nominative case. Therefore "der" is correct.
Ali hat einen Beruf, der ihm gut gefällt.
If you took the construct "jemand (Nom) liebt etwas (Akk)" you'd have a different relationship. Then the object will be the job, the subject the person:
Ali hat einen Beruf, den er sehr liebt.