Let $P_o$ denote the position with the coordinates $(1,0,0)$ in the Descartes coordinate system $(x,y,z)$.
The point $P_o$ is rotated about the z-axis so that the line $OP$ turns directly towards the positive y-axis through an angle $\phi$. The position of the point after this rotation is denoted by $P_1$
$P_1$ is then rotated about the line in the x-y plane perpendicular to $OP_1$ so that the line $OP$ turns directly towards the positive z-axis through an angle $\lambda$, giving $P_2$. Find the coordinates of $P_2$
Initially I approached this question using the spherical coordinates: $$x=r\sin(\theta)\cos(\phi), y=r\sin(\theta)\sin(\phi), z=r\cos(\theta) \tag{1}$$ where $\theta$ is the polar angle and $\phi$ the azimuthal angle.
Setting $\theta=\frac{\pi}{2}-\lambda$ and $\phi=\phi$ gave me the correct the answer: $$P_2=(\cos(\phi)\cos(\lambda),\sin(\phi)\cos(\lambda),\sin(\lambda))\tag{2}$$
However, I then tried an alternative method by rotating the coordinate axes and an incorrect answer was obtained:
I rotated the coordinate axes $(x,y,z)$ by the angle $\phi$ anticlockwise about the z-axis. Denoting the new coordinate axes by $(\bar{x},\bar{y},\bar{z})$, we have $$\begin{align} x&=\bar{x}\cos(\phi)-\bar{y}\sin(\phi)\\ y&=\bar{x}\sin(\phi)+\bar{y}\cos(\phi)\\ z&=\bar{z}\end{align} \tag{3}$$
since $$ \left(\begin{matrix} x\\y\\z \end{matrix} \right)=\left(\begin{matrix} \cos{(\phi)}&-\sin(\phi)&0 \\ \sin(\phi)&\cos(\phi)&0\\0&0&1\end{matrix}\right) \left(\begin{matrix} \bar{x}\\ \bar{y} \\ \bar{z} \end{matrix}\right) \tag{4}$$
Now in the $(\bar{x},\bar{y},\bar{z})$ coordinate system, $P_1$ has the coordinates $(1,0,0)$.
Rotating $P_1$ through the angle $\lambda$ anticlockwise about $\bar{y}$ gives $P_2$
$$\left(\begin{matrix} \cos(\lambda)&0&\sin(\lambda)\\0&1&0\\-\sin{(\lambda)}&0&\cos(\lambda) \end{matrix}\right) \left( \begin{matrix}1\\0\\0 \end{matrix}\right)=\left(\begin{matrix}\cos(\lambda)\\0\\-\sin(\lambda) \end{matrix}\right)=\left(\begin{matrix}\bar{x}\\\bar{y}\\\bar{z}\end{matrix}\right) \tag{5}$$
Solving for $x,y$ and $z$ via $(3)$ in the original coordinate system yields
$$P_2=(\cos(\phi)\cos(\lambda),\sin(\phi)\cos(\lambda),-\sin(\lambda))\tag{6}$$
which is not the correct the answer and the problem seems to originate from the $z$ component which has an extra minus sign in front of it.
What conceptual errors are present in my working?