How my iMac turned off
Solution 1:
There are other Questions on Ask Different regarding what the shutdown codes mean - e.g. Where to find shutdown causes errors list? [which links to a list maintained by one of the Ask Different senior members], but I went for the simplest, GUI-based way of finding the data, rather than using terminal.
[I need to know if this still work on Sierra, as comments suggest the data location may now be different]
This is from El Capitan.
Launch Console from Applications/Utilities
On the left, select 'All Messages' then top right in the search box, type 'shutdown'
Note that a Restart does not appear to generate any shutdown message.