Marriage as an agreement has existed in one form or another since Ancient Egypt. Hebrews had marriage as a contract and an obligation hence the Ancient requirement that a brother take his sister in law as his wife if his brother died. As a sacrament that comes from Paul, in one of his letters to someone, (Ephesisans I think without going to look it up right now).