All perfect praise be to Allah, The Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad is His slave and Messenger.
As long as you had started leaving Mina, then there is no sin on you for leaving it if the sun had set while you were still in it. Also, you did not have to stay in Mina that night and you do not have to offer a sacrifice for this. Shaykh Ibn 'Uthaymeen said: "One (the pilgrim) does not have to stay overnight in Mina if the sun sets while one is in Mina on the twelfth day for something which is beyond his control. For example, if one sets out and rides the vehicle, but due to traffic congestion or the large number of pilgrims, one gets delayed and the like. This is because his staying until sunset was involuntary." [End of quote]
Allah Knows best.