Late 2013 Macbook Pro turns off at random times
try booting into safe mode and test out the machine and see if it powers off. To boot into safe mode, hold down the Shift key when you power it on. Test it and see if it happens again. If not, it could be a third-party application or extension.
Have you updated to macOS Mojave? I had this same issue on my 2012 15" MacBook Pro and nothing I tried fixed it but since I installed Mojave it hasn't happened anymore. Maybe Apple knew about it and the only way to fix it was in the operating system. I didn't actually try taking it to an Apple store though, so maybe there was a different fix for it.