The Sharks failed in their bid to win back-to-back games for the first time this season.
Jonathan Cheechoo scored on a slap shot with 4:29 remaining in the second period to lift San Jose into a 2-2 tie, but Chris Osgood was perfect in the third, while the Red Wings were producing the deciding goals.
Ellis scored his first goal of the season at 7:34 of the third on a backhander that eluded Evgeni Nabokov.
Detroit had a two-man advantage when Datsyuk scored on a slap shot with 9:20 to play.
San Jose had a 1-0 lead after one, but Niklas Kronwall and Henrik Zetterberg vaulted the Red Wings in front during the first half of the second period.
Detroit had lost in six of its previous seven trips to San Jose.
2014: NFL Cheerleaders [PHOTOS]
UPI Sports Results for September 19, 2014