From time to time, this can happen. If you notice that your handlebars are looser than they should be, you may need to make a quick fix. If the problem is derived from the stem, here is what you can do. To begin, locate the stem of your bike (hint, it is the piece that connects the headset to the bars). You should see an Allen bolt (it's head almost looking like a polygon) and chances are, this has simply become loosened. Before you tighten it, though, ensure the bars are in the correct position so you do not end up wasting your time.
With a standard Allenwrench, tighten the bolt until it is secured. After which, check the bars and see if they are still loose. If not, the problem is solved.