When reducing the size of materials towards the nanoscale, magnetic properties can emerge due to structural variations. Here, we show the reverse effect, where the structure of nanomaterials is controlled by magnetic manipulations. Using the break-junction technique, we find that the interatomic distance in platinum atomic wires is shorter or longer by up to ∼20%, when a magnetic field is applied parallel or perpendicular to the wires during their formation, respectively. The magnetic field direction also affects the wire length, where longer (shorter) wires are formed under a parallel (perpendicular) field. Our experimental analysis, supported by calculations, indicates that the direction of the applied magnetic field promotes the formation of suspended atomic wires with a specific magnetization orientation associated with typical orbital characteristics, interatomic distance, and stability. A similar effect is found for various metal and metal-oxide atomic wires, demonstrating that magnetic fields can control the atomistic structure of different nanomaterials when applied during their formation stage.