Study of the B→J/ψK−π+π− decay and measurement of the B→X(3872)K− branching fraction