The ratio of branching fractions R(D*−)≡B(B0→D*−τ+ντ)/B(B0→D*−μ+νμ) is measured using a data sample of proton-proton collisions collected with the LHCb detector at center-of-mass energies of 7 and 8 TeV, corresponding to an integrated luminosity of 3fb−1. The τlepton is reconstructed with three charged pions in the final state. A novel method is used that exploits the different vertex topologies of signal and backgrounds to isolate samples of semitauonic decays of b hadrons with high purity. Using the B0→D*−π+π−π+decay as the normalization channel, the ratio B(B0→D*−τ+ντ)/B(B0→D*−π+π−π+) is measured to be 1.97±0.13±0.18, where the first uncertainty is statistical and the second systematic. An average of branching fraction measurements for the normalization channel is used to derive B(B0→D*−τ+ντ)=(1.42±0.094±0.129±0.054)%, where the third uncertainty is due to the limited knowledge of B(B0→D*−π+π−π+). A test of lepton flavor universality is performed using the well-measured branching fraction B(B0→D*−μ+νμ) to compute R(D*−)=0.291±0.019±0.026±0.013, where the third uncertainty originates from the uncertainties on B(B0→D*−π+π−π+)and B(B0→D*−μ+νμ). This measurement is in agreement with the Standard Model prediction and with previous measurements.