Have you been able to try another headset with your phone in order to see whether the phone works better with another headset or not? Also, try cleaning the headset jack with a wooden or plastic toothpick to keep the jack free from lint and grime.
Another thing that you can try is to reboot your phone in safe mode to see if the headset works better there. All apps downloaded from Play Store is temporarily deactivated while in safe mode and by doing this, you can see if this behaviour is caused by a downloaded app. For more information on safe mode and how to use it, clickhere.
If the behaviour of the headphone jack persists in safe mode, my suggestion is to try to repair the softwareusing a computer and Xperia Companion. Keep in mind though that a software repair will erase all user data from the phone, so make sure to do abackupof your user data before the repair.
If none of these measures manages to improve the functionality of the headphone jack, I suggest that youget in contact with yourlocal support teamin order to have your phone sent to an authorized service center to be examined and possibly repaired. If you have any questions regarding the service such as routines, warranty and consumer laws, these kind of questions are best answered by your local support team as well.