How was the second law of thermodynamics created?
The second law of thermodynamics is more of a basic postulate of the theory without any derivation.
Well, it was formulated from observations from nature and natural processes.
But, the converse process is not true and it is a fact of nature. If you put some heat into an idealised engine, it will still give of a lesser amount of work than the amount of heat you put into it. It shall reject the remaining heat to the surroundings.
Thus, the process of complete conversion of heat into work is not possible in any finite number of cycles in which the engine operates.
That's the second law.
Though there are other forms of the second law, all of them are logically equivalent.
Second law is mainly deduced from observations from nature.
Although later, Clausius formulated an elegant mathematical form of the second law in which he introduced the concept of entropy.
To summarize, the second law assigns the direction in which a natural process evolves.
We always find that natural processes always evolve in one direction spontaneously, that direction of evolution is given by the second law.
For example, consider flow of heat from one body to another spontaneously.
Everyone has observed such a flow from a hotter body to a colder body naturally but, no one has observed the converse process happen naturally.
This direction is specified by the second law.