A habitat is a place where an organism (animal, plant, human) lives, but an ecosystem is a group of organisms plus its surrounding environment.
habitat: the natural home or environment of an animal, plant, or other organism: wild chimps in their natural habitat. (Oxford Dictionary of English)
ecosystem: a biological community of interacting organisms and their physical environment. the marine ecosystem of the northern Gulf had suffered irreparable damage. (Oxford Dictionary of English)