I presume $R'$ is also an $A$-algebra. Since $P$ is a polynomial ring over $A$, the projection map $P\to R$ factors through $R'\to R$ via an algebra map $\phi:P\to R'$ (just pick suitable images for $x_1,\ldots,x_n$). All one has to do is to show that $\phi(I^2)={0}$ in $R'$, for then one gets a map $P/I^2\to R'$, etc. Let $f:R'\to R$ denote the map from the second exact sequence. If $a$, $b\in I$ then $f(\phi(a))=0$ and $f(\phi(b))=0$. Then $\phi(a)$, $\phi(b)\in J$ so $\phi(ab)=0$. This does it.