A thing that felt hunger when it was low on fuel due to pure random chance survived. One that didn't perished instantly. Even with living things, the setting of the goal was not from its own agency, but pure random chance, that led to survival..
So the goal was never surviving, it is just that the ones who's random goals that aligned with survival, survived, and passed on that random flick of some switch via genes.
I guess what I am trying to say is that this does not necessarily need or require AGI..