From Wikipedia:
Ambergris is usually passed in the fecal matter. Ambergris that forms a mass too large to exit via the anus is expelled via the mouth, leading to the reputation of ambergris as primarily coming from whale vomit.