“That” introduces a restrictive clause, and “which” introduces a non-restrictive or parenthetical clause. When in doubt, “which” always takes a comma before it, and “that” does not take a comma: I drove a rental car that was left for me by the agency. I drove a rental car, which was left for me by the agency.