Semiconductor nanowires have received much attention owing to their potential use as building blocks of miniaturized electrical(1), nanofluidic(2) and optical devices(3). Although chemical nanowire synthesis procedures have matured and now yield nanowires with specific compositions(4) and growth directions(5), the use of these materials in scientific, biomedical and microelectronic applications is greatly restricted owing to a lack of methods to assemble nanowires into complex heterostructures with high spatial and angular precision. Here we show that an infrared single-beam optical trap can be used to individually trap, transfer and assemble high-aspect-ratio semiconductor nanowires into arbitrary structures in a fluid environment. Nanowires with diameters as small as 20 nm and aspect ratios of more than 100 can be trapped and transported in three dimensions, enabling the construction of nanowire architectures that may function as active photonic devices. Moreover, nanowire structures can now be assembled in physiological environments, offering new forms of chemical, mechanical and optical stimulation of living cells.