It used to look like the last picture when i just got it
This process is called etiolation, and is caused (like you already mentioned) by insufficient sunlight. Cacti are very prone to etiolation because they need a lot of direct sunlight, so you see this very often with cacti.
You ask can I save it? The good news is, yes. If you'll give the cactus sufficient light from now on (that means at least 5-6 hours direct sunlight a day), the cactus will survive. If you mean by saving, getting the shape back like before this happened? The answer is no, the thin growth is permanent. Only way to reshape it is to prune... I would wait a little if I had this situation, let it grow for a while properly now, and see if you can reshape it later.