Given an arbitrary graph, we describe the center of its Leavitt path algebra over a commutative unital ring. Our proof uses the Steinberg algebra model of the Leavitt path algebra. A key ingredient is a characterization of compact open invariant subsets of the unit space of the graph groupoid in terms of the underlying graph: an open invariant subset is compact if and only if its associated hereditary and saturated set of vertices satisfies Condition (F). We also give a basis of the center. Its cardinality depends on the number of minimal compact open invariant subsets of the unit space.