Though sage Krishna Dvaipayana, commonly known as Vyasa, laid down the theory of Karma Yoga in his famous Bhagawadagita and said that Moksha (मोक्ष) or salvation can be achieved by following the path of Karma Yoga, the genesis of the thought, I think, lies in the 40th chapter of Yajurveda which has come to be known as Isha Upanishadha.
The very first shlok or verse of the Isha Upanishadh says:
ईशावास्यमिदं सर्वं यत्किञ्च जगत्यां जगत् ।
तेन त्यक्तेन भुञ्जीथा मा गृधः कस्य स्विद्धनम् ॥ १ ॥
Isha, (the Lord) exist everywhere and in everything in this dynamic world that we see round us;
Use (or consume/enjoy) the worldly things with dispassionate abstinence — without attachment — for who owns the wealth forever?
The Hindu scriptures emphatically say that the Brahama and the empirical world, both are real and infinite — mirror images — so to say. What is limited is our life-span and that you cannot enjoy the worldly things forever. Then why the heck are you getting attached with them?
The Sanskrit word Karma (कर्म) has evolved from the root letter कृ which stands for a verb, meaning “action” or “activity” and the word yoga means “addition”, “combination”, “joining” or “a situation”. In Bhagawadagita Lord Krishna exhorts Arjuna to take a posture of non-attachment and aloofness in which the duty is the prime factor, irrespective of who wins or loses in the battle or who gets hurt or is killed.
“Thy duty is to fight,” Krishna tells Arjuna.

In Bhagawadagita chapter 2 shlok 38 Krishna says:
सुखदु:खे समे कृत्वा लाभालाभौ जयाजयौ |
ततो युद्धाय युज्यस्व नैवं पापमवाप्स्यसि || 38||
Treating joy and sorrow, victory and defeat alike, get ready for the battle for that’s the only way you won’t incur sin.
Again in Bhagawadagita chapter 2 shlok 47 Krishna tells Arjuna:
कर्मण्येवाधिकारस्ते मा फलेषु कदाचन |
मा कर्मफलहेतुर्भूर्मा ते सङ्गोऽस्त्वकर्मणि || 47 ||
The only thing within your volition or free will is to do your duty or karma, its reward is beyond your volition. Neither should you deem yourself capable enough to extract a reward for your action, nor should you resort to inaction because the reward is not assured.
In the following shlok (Chapter 2, shlok 48) Krishna tells Arjuna to posit himself in the posture of dispassionate non-attachment or to live life with dispassionate aloofness:
योगस्थ: कुरु कर्माणि सङ्गं त्यक्त्वा धनञ्जय |
सिद्ध्यसिद्ध्यो: समो भूत्वा समत्वं योग उच्यते || 2.48||
O Arjuna, do they duty with un-attached disposition, for accomplishment and failure are just two sides of the same coin. Treat them equally, with respect. This mental state of dispassionate disposition and equanimity is called “Yoga”.
The crux of the Karma Yoga, as described in Bhagawadagita and many Upanishadhs is to do your duty or karma in such a way so as to render your karmas or deeds absolutely neutral.
The philosophy behind karma, as elucidated and elaborated in Hindu scriptures is, that behind all our deeds and activities it is the “intent” or our “disposition” that matters most. According to the Biblical theory “the sin is the willful transgression against the law of God.” Willfulness means intent. This argument has been magnanimously adopted by the Greek Law and the modern jurisprudence where emphasis lies on intent of the offender.The Hindu scriptures take this theory to its extreme: no intent, no offence and therefore no guilt.
Bhagawadagita presents the same line of argument in a different way. It seeks to shrink our ego/self to a naught where our “I” becomes a non-entity and our body-and-Self/ego becomes a mere tool, an instrument (nimitta निमित्त) in the activity. Thus, if you do your karma with absolute non-attachment and aloofness as if being a mere tool or instrument, your karmas will incur no sin — and that’s what has been explained in Bhagawadagita. A soldier who kills an enemy in a battle just performs his duty: a tool, an instrument who has to perform his duty — to kill. No guilt, no acrimony and no sadness! That’s because the soldier who kills his enemy does so on the orders of the State and deems his benign duty to do so.
In chapter 4, shlok 14 of Bhagawadagita Krishna explains this in his own way:
न मां कर्माणि लिम्पन्ति न मे कर्मफले स्पृहा।
इति मां योऽभिजानाति कर्मभिर्न स बध्यते ॥14॥
Neither do my karmas (actions) involve my Self, nor do I get attached to the fruits of my actions. Neither I am the doer of my actions nor do I expect returns for my deeds. Those who know me thus, do not get bound by the karmic reactions.
In chapter 4 shlok 19 Krishna explains:
यस्य सर्वे समारम्भा: कामसङ्कल्पवर्जिता: |
ज्ञानाग्निदग्धकर्माणं तमाहु: पण्डितं बुधा: || 19||
The one whose all karmas are without expectations and whose karmas have been neutralised by the sublime/divine wisdom, such persons are called pundit.
This shloka is comprised of two compound words namely कामसङ्कल्पवर्जिता and ज्ञानाग्निदग्धकर्माणं . The real meaning of these words will be clear once we break them down. The word कामसङ्कल्पवर्जिता: is actually a compound of three words: काम (desire) + संकल्प (determination) + वर्जिता (without/sans) — and thus the word कामसङ्कल्पवर्जिता: works out to mean “without a pre-determined desire”. Like-wise the compound word ज्ञानाग्निदग्धकर्माणं is comprised of four words namely ज्ञान (wisdom/sublime knowledge) + अग्नि (fire) + दग्ध (burnt) + कर्मा karma (deeds). Thus, the compound word ज्ञानाग्निदग्धकर्माणं will work out to mean “karmas or deeds having got burnt out in the fire of wisdom or sublime/divine knowledge” and thereby rendered ineffectual or neutral.
In Sanskrit literature a metaphor has often been used. It???s called dagdhabeej (दग्धबीज्). It literally means a “burnt seed” which can’t produce a plant. The word ज्ञानाग्निदग्धकर्माणं relies on the same metaphor and literally means the “karmas which have been burnt out by the fire of sublime/divine knowledge or wisdom.” Since the karmas have been burnt out, they would no longer produce bad or good effects and save one from the cycle of rebirth and lead to salvation.
The shlok 20 of chapter 4 sums up the Karma Yoga in a few words.
त्यक्त्वा कर्मफलासङ्गं नित्यतृप्तो निराश्रय: |
कर्मण्यभिप्रवृत्तोऽपि नैव किञ्चित्करोति स: || 20||
The one who sheds his desire/greed for returns and is content and satisfied with his own self, such a person despite being involved in his karma/activity/deed in fact does not do any karma.
Thus, the essence of the Karma Yoga is that one should not get attached to the fruits of deeds or expect returns from one’s karma — and this will save one from the cycle of endless rebirths and lead one to salvation.