We have already learned that の can act as a noun when modified by an adjective:
赤いのを ください。
Please give me the red one.
Not surprisingly, の can also be used with verbs.
We have already seen that こと can be used to turn a verb into a noun:
テニスをすることが 好きです。
I like playing tennis.
の behaves in much the same way:
テニスをするのが 好きです。
I like playing tennis.
However there is a difference: こと refers to a verb in an abstract kind of way, “the act of playing tennis” or “to play tennis”, whereas の has a much more immediate feel to it “that I play tennis” or “when I play tennis”.