The detail story of Janaka attaining perfection in karma yoga and then liberation is present in the earlier chapters of Upasama Kanda of Yoga Vasista.
Janaka, king of Videha, heard the songs of Siddhas in garden and then started vicharana based on the songs of the siddhas. He concluded as a part of vicharana that nishkama karma is a best way to perform karma and followed the same. As a consequence of that Janaka achieved liberation.
Just as the effulgent sun in the Ākāśa causes days, etc., to happen
without any volition or desire on their part, so also Janaka
contemplated upon performing, without any longing, all actions of his
life which crop up spontaneously every day. So never for a moment
ruminating upon the past or future, productive as they are of evil, he
began at once to transact his present actions with a full heart. Only
through the Ātmic enquiry created by the words of the Siddhas, did
Janaka attain quiescence of mind and Ātma-jñāna.
[The Story Of King Janaka, Upaṣānti-prakaraṇa (chapter 5), Laghu-yoga-vasistha]