First let f(b) = f(a) = 0. This is a special case of the mean value theorem, and is sometimes called Rolle's theorem. Since f is continuous over a closed bounded interval, it attains a maximum somewhere, call it c. If c is either a or b, and nothing in between, place c at the minimum of f. If c is again a or b, then f is 0 throughout, so let c be the midpoint of a and b. Thus f attains a local maximum, or minimum, or both at c, hence f′(c) = 0, which matches the slope of the connecting segment.
When f(a) and f(b) are not constrained, you simply tilt your head, so that the connecting segment looks horizontal. This can be done algebraically. If s is the slope of the chord, consider the function f(x) - s×(x-a) - f(a), and apply Rolle's theorem. Sure enough, f′(c) = s.