When executing sapcontrol -nr <instance> -function Stop it returns the error “FAIL: HTTP Error, HTTP/1.1 401 Unauthorized“

Fixing this error is simple with the below steps:
1- Using (1) ps -ef | grep sapstartsrv to identify the process id of the sapstartsrv process as shown below. In the below case we can see that it is the process 6100. (2) Kill that process using kill -9 6100.

After you killed the process, if you try using sapcontrol it should return: FAIL: NIECONN_REFUSED (Connection refused), NiRawConnect failed in plugin_fopen().

Just start the service again using sapcontrol -nr <instance> -function StartService <SID> or start again sapservices, which should be under /usr/sap/ as shown below:

Try starting/stopping the system again and it should work.

Regards.