Hi and Welcome. My Name is ***** ***** I look forward to assisting you today with your question.
From your description, it is possible that your Mac's hard drive is failing. Issues with hard drive usually cause it to turn off automatically as it can't read the OS X properly from the hard drive. Since you are able to boot into OS X Utilities screen, that means all other components like logic board, RAM, processor etc are fine. It is just the hard drive.
First we can run Disk Utility and then we can try to reinstall the OS X and see if it works or not.
You said you are in Utilities. Click Disk Utility. In Disk Utility, select Macintosh HD (or your hard disk) in left column. Click First Aid and run it. This will fix some system files. Then close it.
Click Reinstall Mac OS X in there. Then follow the onscreen instructions to reinstall. You will not be able to reinstall if the hard drive is failed. You will get stuck at choose disk or may fail during installation. If this is an hard drive issue (if you are unable to reinstall), then I'd recommend to take it to the Apple Store and you need to get the hard drive replaced. If it is under warranty, then Apple will replace the hard drive without any cost. Or it will cost up to $200 to replace the hard drive.
Let me know how it goes.