A two-way solenoid valve with three ports, intended to regulate the passage of a fluid flow between a first inlet in the direction of a second outlet and/or a third outlet, comprising a fixed core housed inside an outer casing and a movable core that can be axially displaced through a hole relative to said fixed core by the action of a force generated by a magnetic field, in which a drive shaft linked to the movable core is also provided, which drive shaft has sealing means at one end that act on the first inlet and/or second and third outlets to allow their fluid communication, the magnetic field being governed by a control board, wherein it includes a pressure compensation system that links the pressure value at the first inlet and the pressure value at the second and third outlets and, the pressure compensation system being associated with the displacement of the drive shaft, and the sealing means comprise a sealing element wherein in a first operating OFF condition of a current supply for generating the magnetic field, the first inlet and the third outlet are in fluid communication, while in a second operating ON condition where there is a current supply for generating the magnetic field to displace the movable core, the first inlet and the second outlet are in fluid communication so that the pressure value of the second outlet is equal to the pressure value of the first inlet and the pressure present in the third outlet and a compensating chamber is the same, wherein the pressure compensation system comprises a first passage that connects the third outlet with the compensating airtight chamber, the compensating chamber being in fluid communication with the second outlet through an orifice that can be sealed by means of sealing gaskets; characterised in that the pressure compensation system comprises an elastic return system for the drive shaft, comprising a main elastic element and a secondary elastic element that are spaced apart, and in that the secondary elastic element has more elastic force than the main elastic element so that movement of the sealing element is prevented in such second operating condition where the pressure value of the second outlet is in balance of forces with the pressure value of the third outlet, the pressure value of the second outlet being equal to the pressure value of the first inlet. wherein the pressure compensation system comprises a first passage that connects the third outlet with the compensating airtight chamber, the compensating chamber being in fluid communication with the second outlet through an orifice that can be sealed by means of sealing gaskets; characterised in that the pressure compensation system comprises an elastic return system for the drive shaft, comprising a main elastic element and a secondary elastic element that are spaced apart, and in that the secondary elastic element has more elastic force than the main elastic element so that movement of the sealing element is prevented in such second operating condition where the pressure value of the second outlet is in balance of forces with the pressure value of the third outlet, the pressure value of the second outlet being equal to the pressure value of the first inlet.