Open the Force Quit dialogue;
> Force Quit, select Safari and click to quit
(alternatively try opt -cmd-esc to open the window)
Then try shut down again.
If the problem persists, use your free telephone support to
a) get more ideas
b) register the fact that you have a problem with your new Mac
Ultimately if it continues, you can return the Mac for a refund or replacement as long as it's within the first 14 days.