Emission of two short hard X-ray bursts on 2009 June 5 disclosed the existence of a new soft gamma-ray repeater, now catalogued as SGR 0418+5729. After a few days, X-ray pulsations at a period of 9.1 s were discovered in its persistent emission. SGR 0418+5729 was monitored almost since its discovery with the Rossi X-ray Timing Explorer (2–10 keV energy range) and observed many times with Swift (0.2–10 keV). The source persistent X-ray emission faded by a factor of ∼10 in about 160 d, with a steepening in the decay about 19 d after the activation. The X-ray spectrum is well described by a simple absorbed blackbody, with a temperature decreasing in time. A phase-coherent timing solution over the ∼160 d time-span yielded no evidence for any significant evolution of the spin period, implying a 3σ upper limit of 1.1 × 10−13 s s−1 on the period derivative and of ∼3 × 1013 G on the surface dipole magnetic field. Phase-resolved spectroscopy provided evidence for a significant variation of the spectrum as a function of the stellar rotation, pointing to the presence of two emitting caps, one of which became hotter during the outburst. Finally, a deep observation of the field of SGR 0418+5729 with the new Gran Telescopio Canarias 10.4-m telescope allowed us to set an upper limit on the source optical flux of i′ > 25.1 mag, corresponding to an X-ray-to-optical flux ratio exceeding 104, consistent with the characteristics of other magnetars.