For a (molecular) graph, the first Zagreb index $M_1$ is equal to the sum of squares of its vertex degrees, and the second Zagreb index $M_2$ is equal to the sum of products of degrees of pairs of adjacent vertices. A connected graph $G$ is a cactus if any two of its cycles have at most one common vertex. We investigate the first and the second Zagreb indices of cacti with $k$ pendant vertices. We determine sharp bounds for $M_1$-, $M_2$-values of $n$-vertex cacti with $k$ pendant vertices. As a consequence, we determine the $n$-vertex cacti with maximal Zagreb indices and we also determine the cactus with a perfect matching having maximal Zagreb indices.