We present the results of a search for short- and intermediate-duration gravitational-wave signals from four magnetar bursts in Advanced LIGO's second observing run. We find no evidence of a signal and set upper bounds on the root sum squared of the total dimensionless strain (<i>h</i><sub>rss</sub>) from incoming intermediate-duration gravitational waves ranging from 1.1 <b>×</b> 10<sup>−22</sup> at 150 Hz to 4.4 <b>×</b> 10<sup>−22</sup> at 1550 Hz at 50% detection efficiency. From the known distance to the magnetar SGR 1806–20 (8.7 kpc), we can place upper bounds on the isotropic gravitational-wave energy of 3.4 <b>×</b> 10<sup>44</sup> erg at 150 Hz assuming optimal orientation. This represents an improvement of about a factor of 10 in strain sensitivity from the previous search for such signals, conducted during initial LIGO's sixth science run. The short-duration search yielded upper limits of 2.1 <b>×</b> 10<sup>44</sup> erg for short white noise bursts, and 2.3 <b>×</b> 10<sup>47</sup> erg for 100 ms long ringdowns at 1500 Hz, both at 50% detection efficiency.