In one of the concluding scenes of the movie Thor, it's shown that Loki deliberately let go of the scepter, and falls deep into the vast intergalactic sea sort of thing. How does he survive and return in the Avengers movie?
It's heavily hinted that he was rescued by the Chitauri. In one scene, we see the character identified as The Other, scolding Loki:
The Other: You question us? You question him? He who put the scepter in your hand. Who gave you ancient knowledge and new purpose when you were cast out. Defeated!
In the course of the movie, it is revealed that the Chitauri struck a deal with Loki. He would help them get the Tesseract, and they would help him conquer Earth.
Presumably, he used his magic, which is quite powerful, to navigate the wormhole the Bifrost had opened. I don't know whether he sensed Thanos and navigated toward his presence or if Thanos sensed him and pulled him in or if Loki just happened to set himself down on a planet Thanos occupied. But he survived through sorcery.