It's likely that the hinge needs tightening or replacing as Allan suggests, I would strongly urge that you take this into Apple for service as they are the best equipped to do this.
However there are guides online on how to fix this issue, it requires following the take apart guides available online including from sites such as iFixit, and adjusting the screws.
The following guide seems pretty clear cut to me, usually I'd write out the instructions, but the photos are useful here and there are numerous other guides:
What I will stress however is that you backup you Mac, and recognise that you could damage the device beyond repair by servicing it yourself and that Apple and their Apple Authorised Service Providers will not service any product which has been serviced by an unauthorised provider, including yourself.
i.e. If this isn't your main computer, then fine, but if this is your only computer, you have no plans to buy a new one soon, and it's not a major issue then I would not attempt this repair.