Pandita, I once had the same experience. No doubt thousands or even tens of thousands of people have been horrified, seeing the lower headset bearings fall out.
Now you know that next time you're taking the fork off, you'll have the frame upside-down, with fork pointed up to the ceiling. If you have new grease, should clean everything and put all the bearings back in place with plenty of new grease. If the bearings are not perfectly shiny, smooth and fitting, it's time for new ones. Good luck with your repairs and better biking.