Did you preset the altitude, navigation source or correct heading, speed, etc prior to engaging the autopilot? If all you did was take off, point the plane in a general direction and punch on the AP, that’s not going to end well and could be the cause of your issue.