Aren't these two opposed to each other? Which one should we follow?
It depends on what you want to attain.
There are 3 types of action - karma, vikarma, akarma
karma - doing an action ordained by shastras (dharma) with desire to attain its fruits - this is what you and I do 99% of time
vikarma - doing an action NOT ordained by shastras (adharma) with desire to attain its fruits - what 'bad' people do.. and they won't even get its results, or the results won't last long.
akarma (it means non-action, but real meaning is different) - doing an action ordained by shastras (dharma) WITHOUT desire to attain its fruits
Akarma and Nishkama karma are synonyms.
e.g. going to work and earning money, but only for the sake of taking care of parents, wife & children, poor & disabled charity etc.. and not having any personal interest in using the money to buy cars, houses, computers etc. even though they are used in part of daily duties.
how does akarma/nishkama karma help you ?
when you do anything with desire to attain fruits, you have to wait until the result bears fruit. so that waiting period is spent in worry.
if you do not obtain the desired result (it's because you didn't do the work properly, or it was done against shastras), then you get angry. again, this causes pain.
if you obtain the desired result, you enjoy it.. great. but it creates 'vasana' or impressions in mind, that drive you to work and obtain the result again and enjoy it again (like a fire that does not subside when you feed it ghee, but only increases in strength). Now, you are back to square 1, because when you try to do that work again, same 3 options above can happen.
Whereas when you do nishkama karma, your only goal is to do the job, not wait for its results, so there is no waiting period, no worry about not getting the result, and no vasanas to further force you into more work.
so why would anybody do nishkama karma at all ?
Think of your life on earth as a debt to be repaid. Once you repay it (by nishkama karma), you're free (moksha). But during the process of repaying, if you take more loans or credit (by creating more desires and vasanas), you have to be born again to repay the debt. And it's a never ending cycle.
Purusharthas - dharma, artha, kama - if they are done as karma, it can bind you to samsara. The same purusharthas, if they are done as akarma/nishkama karma, as a duty to parents, rishis, devas, gurus, family - it frees you from samsara.