For the sake of future readers, I'd like to add some clarification on the solution which has been posted before.
First, note that the center of a $p$-group is nontrivial. Hence, the center is of order either $p$ or $p^2$. $|Z(G)|=p^2$ is impossible because $|Z(G)|=p^2$ implies that $|\frac{G}{Z(G)}|=p$, and hence $\frac{G}{Z(G)}$ is cyclic. Therefore, $G$ is abelian, which is against our assumption.
Therefore, $|Z(G)|=p$, and $|\frac{G}{Z(G)}|=p^2$. Since any group of order $p^2$ is abelian , we conclude that $\frac{G}{Z(G)}$ is abelian. Now, for all $x,y \in G$, we have:
$(xZ(G))(yZ(G))=(yZ(G))(xZ(G))$. So,
$$1Z(G)=(xZ(G))^{-1}(yZ(G))^{-1}(xZ(G))(yZ(G)) \\ =x^{-1}y^{-1}xyZ(G)=[x,y]Z(G).$$
Thus, $[x,y]\in Z(G)$ for all $x,y\in G$, so $[G,G] \leq Z(G)$. However, note that $Z(G)$ is a group of order $p$ whose only subgroups are $e$ and $Z(G)$. Since $[G,G]$ is nontrivial (if it were trivial, $G$ would have been abelian), we must have $[G,G]=Z(G).$