Yes, Hashirama stabbed him but in reality .. Madara programmed his eye to activate the izanami or izanagi ( vateva ) to change his destiny incase he was killed ! So by the izanagi or izanami ( vateva ) he was able to survived ! Then he used a shadow clone to replace himself in the coffin !! I hope I made sense cuz this is what happened !! Read the manga for more spoiling XD