Consider two systems, 1 and 2, which can exchange heat and do only the mechanical p-V work. They are isolated from the rest of the world. At equilibrium they have the common pressure, say $\bar p$. Then if we nudge them slightly from equilibrium, then we must have, because of isolation, that (I denote by $E$ the internal energies)
\begin{align*}
\text{total increase in energy } &=(dE_1 - \bar p\;dV_1) + (dE_2 - \bar p\;dV_2)\\
&= d(E_1 + E_2 -\bar p(V_1 + V_2))
\end{align*}
be zero, and hence
$$
E_1 + E_2 = \bar p(V_1 +V_2) + \text{const.}\tag{1}
$$
Now, assuming that the systems are independent,
$$
S_\text{tot}(E_1, E_2, V_1, V_2) = S_1(E_1, V_1)+S(E_2, V_2).\tag{2}
$$
Now, maximizing (2) subject to (1) leads that, at equilibrium,
$$
\frac{\partial S_1}{\partial E_1} = \frac{\partial S_2}{\partial E_2}
$$
which we identify as $1/T$, and
$$
\frac{\partial S_1}{\partial V_1} = -\frac{\bar p}{T},
$$
which contradicts the oft-stated result with the minus sign flipped.
In hindsight, there must be a minus sign on the RHS of the constraint (1), but I don't see why.
Question: What exactly has gone awry in the above reasoning of mine?