Equivalence between Lorenz gauge and continuity equation I want to show that the Lorenz gauge condition$$
\nabla\cdot \mathbf{A} + \frac{1}{c^2}\frac{\partial\Phi}{\partial t}~~=~~0
\,,$$where $\mathbf{A}$ and $\Phi$ are the vector and scalar potential of the electromagnetic field, is equivalent to the continuity equation$$
\nabla \cdot \mathbf{J}+\frac{\partial \rho}{\partial t}~~=~~0
\,,$$
where $\mathbf{J}$ is the electric current and $\rho$ the charge density, using the general expression of the potential using retarded Green functions$$
\begin{alignat}{7}
\Phi & ~~=~~ & \frac{1}{4\pi\varepsilon_0} & \int \mathrm{d}^3x' \frac{\rho\left(\mathbf{x'},t-\frac{1}{c}|\mathbf{x}-\mathbf{x'}|\right)}{|\mathbf{x}-\mathbf{x'}|} \\
\mathbf{A} & ~~=~~ & \frac{\mu_0}{4\pi} & \int \mathrm{d}^3x' \frac{\mathbf{J}\left(\mathbf{x'},t-\frac{1}{c}|\mathbf{x}-\mathbf{x'}|\right)}{\left|\mathbf{x}-\mathbf{x'}\right|}
\end{alignat}
$$
My first instinct is to simply plug the expression of the potential in the Lorenz gauge, which yields$$
\begin{alignat}{7}
\nabla\cdot \mathbf{A} + \frac{1}{c^2}\frac{\partial\Phi}{\partial t} & ~~=~~
&& \frac{\mu_0}{4\pi}\int \mathrm{d}^3x' \nabla_{\mathbf{x}}\cdot\frac{\mathbf{J}\left(\mathbf{x'},t-\frac{1}{c}|\mathbf{x}-\mathbf{x'}|\right)}{\left|\mathbf{x}-\mathbf{x'}\right|} \\
&& ~~+~~ & \frac{\mu_0}{4\pi}\int \mathrm{d}^3x' \frac{\partial}{\partial t}\frac{\rho\left(\mathbf{x'},t-\frac{1}{c}\left|\mathbf{x}-\mathbf{x'}\right|\right)}{|\mathbf{x}-\mathbf{x'}|} \\
\\
&~~=~~&&\frac{\mu_0}{4\pi}
%
\left(
\begin{array}{rl}
  & \displaystyle{\int{\mathrm{d}^3x' \frac{\nabla_{\mathbf{x}}\cdot\mathbf{J}\left(\mathbf{x'},t-\frac{1}{c}|\mathbf{x}-\mathbf{x'}|\right)}{\left|\mathbf{x}-\mathbf{x'}\right|}}} \\
- & \displaystyle{\int{\mathrm{d}^3x' \mathbf{J}\left(\mathbf{x'},t-\frac{1}{c}\left|\mathbf{x}-\mathbf{x'}\right|\right)\cdot\frac{\mathbf{x}-\mathbf{x'}}{\left|\mathbf{x}-\mathbf{x'}\right|^3}}} \\
+ & \displaystyle{\int{\mathrm{d}^3x' \frac{\partial}{\partial t}\frac{\rho\left(\mathbf{x'},t-\frac{1}{c}\left|\mathbf{x}-\mathbf{x'}\right|\right)}{|\mathbf{x}-\mathbf{x'}|}}}
\end{array}
\right)_{\Large{,}}
\end{alignat}
$$
using
$$
\nabla \cdot \psi \mathbf{A} ~~=~~ \psi \nabla\cdot \mathbf{A} + \mathbf{A}\cdot\nabla\psi
\,.$$
Now, the first and last term in the last expression are the continuity equation, but that middle term ruins everything. I don't see why it should be zero, and if it shouldn't, where I'm wrong. 
 A: You're trying to prove the right thing with the wrong assumptions.
The continuity equation and the Lorentz gauge equation describe what is happening at the source's place and time, while the potentials given by the retarded Green's integrals describe what an observer measures far away from the source's place-time. So these two couple of equations can not be directly substituited one into the other, for are not directly related.
For an elegant proof that the Lorentz condition is a direct consequence  of te equation of continuity, take a look into the section 14-5 (The Hertz Potential) of the book: "Classical Electricity and Magnetism" by Wolfgang Panofsky and Melba Phillips.
A: In Griffiths' textbook "Introduction to Electrodynamics" (third edition), Problem 10.8 is "Confirm that the retarded potentials satisfy the Loren(t)z gauge condition". The solution is available on-line (search "introduction to electrodynamics solution manual david griffiths"). A comparison of Griffiths' solution with yours revealed that the first and last terms of your last expression were not the continuity equation, as Julio Moros pointed out in his answer. 
