Context. IRAS 20126+4104 is a well studied B0.5 protostar that is surrounded by a similar to 1000 au Keplerian disk and is where a large-scale outflow originates. Both 6.7-GHz CH3OH masers and 22-GHz H2O masers have been detected toward this young stellar object. The CH3OH masers trace the Keplerian disk, while the H2O masers are associated with the surface of the conical jet. Recently, observations of dust polarized emission (350 mu m) at an angular resolution of 9 arcsec (similar to 15 000 au) have revealed an S-shaped morphology of the magnetic field around IRAS 20126+4104. Aims. The observations of polarized maser emissions at milliarcsecond resolution (similar to 20 au) can make a crucial contribution to understanding the orientation of the magnetic field close to IRAS 20126+4104. This will allow us to determine whether the magnetic field morphology changes from arcsecond resolution to milliarcsecond resolution. Methods. The European VLBI Network was used to measure the linear polarization and the Zeeman splitting of the 6.7-GHz CH3OH masers toward IRAS 20126+4104. The NRAO Very Long Baseline Array was used to measure the linear polarization and the Zeeman splitting of the 22-GHz H2O masers toward the same region. Results. We detected 26 CH3OH masers and 5 H2O masers at high angular resolution. Linear polarization emission was observed toward three CH3OH masers and toward one H2O maser. Significant Zeeman splitting was measured in one CH3OH maser (Delta V-Z = -9.2 +/- 1.4 ms(-1)). No significant (5 sigma) magnetic field strength was measured using the H2O masers. We found that in IRAS 20126+4104 the rotational energy is less than the magnetic energy.