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 (h rss) from incoming intermediate-duration gravitational waves ranging from 1.1 × 10−22 at 150 Hz to 4.4 × 10−22 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 × 1044 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 × 1044 erg for short white noise bursts, and 2.3 × 1047 erg for 100 ms long ringdowns at 1500 Hz, both at 50% detection efficiency.