Both originated during the cold war. First World countries were those who supported the US and Second World were those who supported the USSR. Third World nations were those which did not support either bloc.
The most popularly known instance of this is the Non-Aligned Movement started by Jawaharlal Nehru in India and some other newly independent countries as its founding members. As Third World countries were mostly nations who had just got independence from colonial rule, they were behind in terms of technology, industry etc. That’s why you’ll see “Third World” used in relation to poor nations. These categories don’t hold much meaning anymore so we now use developed and developing nations. But, as these were very popular terms, they are still in use. Sometimes also in ironic phrases like “first world problems” etc.
Latest Answers