We know we may need to perform the major ablution (ghusl) while fasting, and it does not break the fast, but during the ghusl we happen to swallow some water accidentally. Does it break the fast?
You can continue to fast as long as you do not swallow intentionally. The Almighty God has decreed:
“God does not bind anyone with a responsibility which is beyond their capacity. Some of the things a person earns are to their advantage, and some are to their disadvantage. (You should pray as such:) “Our Master, do not hold us responsible if we forget or make a mistake…” (Al-Baqarah 2:286)
It is clear by the verse that we are not held responsible for forgetting or making a mistake, which is an accidental case.
Just as someone who eats by forgetting can keep on the fast, anyone who swallows water accidentally can also keep on the fast without the need of compensation.