We demonstrate precise closed-loop control of microjets under the influence of the magnetic fields in three-dimensional (3D) space. For this purpose, we design a magnetic-based control system that directs the field lines towards reference positions. Microjets align along the controlled field lines using the magnetic torque exerted on their magnetic dipole, and move towards the reference positions using their self-propulsion force. We demonstrate the controlled motion of microjets in 3D space, and show that their propulsion force allows them to overcome vertical forces, such as buoyancy forces, interaction forces with oxygen bubbles, and vertical flow. The closed-loop control localizes the microjets within a spherical region of convergence with an average diameter of 406+/-220 lm, whereas the self-propulsion force allows them to swim at an average speed of 222674 lm/s within the horizontal plane. Furthermore, we observe that the controlled microjets dive downward and swim upward towards reference positions at average speeds of 232+/-40 lm/s and 316+/-81 lm/s, respectively.