The answer to the question by the OP is that the work done by a system can always be evaluated considering movement against the external force (pressure). For a quasi-equilibrium process this work can also be evaluated considering changes in the internal pressure and volume of the gas; but in general for a non quasi-equilibrium, irreversible, process the work cannot be evaluated using changes in the internal pressure and volume in the gas, because the gas is not in a definite state.
A detailed evaluation of work for a gas expanding and pushing a piston follows.
The detailed evaluation also answers a question by @ATHARVA in an earlier comment for a gas expanding and moving a piston. Specifically, why is the weight of the piston not included in the work done by the gas? Based on comments and answers by others, there is confusion about the answer to this question. And, if there is also an external pressure on the piston (e.g., from the atmosphere), and from other forces on the piston due to external loads driven by the piston, why are they also not included in the work done by the gas? The answer is: we are interested in the work done by a system on its surroundings; for the piston example, this is the work done by the gas (the system) on the piston (the surroundings), but this is not the total work done on the piston.
The answers to both these questions follow, using a detailed evaluation of the work done on the piston by a single force, from the pressure of the gas, contrasted with the net work done by the total force on the piston, the vector sum of all forces on the piston: the force from the gas pressure, the weight of the piston, the external atmospheric pressure on the piston, and other forces on the piston due to external loads driven by the piston.
Let the system be defined as the gas in a container, a closed thermodynamic system of constant mass, with a moveable boundary, that being the interface of the gas with a moveable piston on top of the gas. The piston is treated as a rigid body, and a rigid body can have no change in its internal energy (e.g., a rigid body cannot be compressed.) The bottom of the piston is exposed to the gas and the top is exposed to the atmosphere. Initially, the piston at rest. An amount of heat $Q_{gas}$ is added to the gas to move piston upwards in the $\vec x$ direction. We are interested in the work $W_{gas}$ done by the system, the gas, on its surroundings, the piston. $W_{gas}$ is positive due to movement of the piston upwards. From the first law of thermodynamics,
$Q_{gas} - W_{gas} = \Delta U$ where $\Delta U$ is the change in the internal energy $U$ of the gas.
Let $F_{ext}$ (here called the external force) be the total force on the piston from the surroundings external to the system (the gas). $F_{ext}\hat i = -(mg + P_{atm}A + F_{other})\hat i$ where $g$ is the acceleration of gravity, $P_{atm}$ is the atmospheric pressure, $A$ is the area of the piston of mass $m$, $F_{other}$ is the reaction force on the piston from external loads driven by the piston, and $\hat i$ is a unit vector positive upwards. $V$ is the volume of the gas.
In a quasi-equilibrium (slow) process, the piston moves slowly and has zero acceleration; the gas is always in a definite thermodynamic state, and the state changes slowly as the piston moves. Since the piston has zero acceleration, the sum of the all the forces (the total force) on the piston is zero: $F_{ext} \hat i + P_{gas}A \hat i = 0$ where $P_{gas}$ is the gas pressure. (Actually, $P_{gas}A \hat i$ is infinitesimally greater (or less) than $F_{ext} \hat i$ to cause slow movement of the piston upwards (or downwards).) The total work done on the piston is the work done by the gas plus the work done by the external force. Since the total force on the piston is zero, the total work done on the piston is zero. Let $V$ denote the volume of the gas and let $x$ denote the displacement of the piston, taken positive upwards. For movement of the piston $dx$, $dV = Adx$. The total work done on the piston is $\int_{V_1}^{V_2} P_{gas}(V) dV + \int_{x_1}^{x_2} F_{ext} dx = 0$. The work done by the gas on the piston $W_{gas}$ is $\int_{V_1}^{V_2} P_{gas}(V) dV$ and the work done by the external force is $\int_{x_1}^{x_2} F_{ext} dx$. $\int_{V_1}^{V_2} P_{gas}(V) dV$ = $-\int_{x_1}^{x_2} F_{ext} dx$. $\int_{V_1}^{V_2} P_{gas}(V) dV$ can be evaluated if you know the gas pressure as a function of volume. The mass of the piston and the atmospheric pressure do not appear in the work done by the gas $\int_{V_1}^{V_2} P_{gas}(V) dV$, but are accounted for in the work done by the external force $\int_{x_1}^{x_2} F_{ext} dx$. In many problems and examples addressed in basic thermodynamics textbooks, $P_{gas}(V)$ and the change in $V$ are given and the work is evaluated as $\int_{V_1}^{V_2} P_{gas}(V) dV$. This may leave the impression that the $F_{ext}$ is not considered, but since
$\int_{V_1}^{V_2} P_{gas}(V) dV = -\int_{x_1}^{x_2} F_{ext} dx$, $P_{gas}(V)$ and the change in $V$ are implicitly affected by $F_{ext}$. $\int_{V_1}^{V_2} P_{gas}(V) dV$ is the work done by the gas on the piston, not the total work done on the piston, and the work done by the gas on the piston is also equal to $-\int_{x_1}^{x_2} F_{ext} dx$ with magnitude $\int_{V_1}^{V_2} P_{ext}(V) dV$, where $P_{ext} = |F_{ext}|/A$ is the magnitude of the external pressure from the external force on the piston. In summary, for a quasi-equilibrium process, the work done by the gas on the piston can be evaluated using either $\int_{V_1}^{V_2} P_{gas}(V) dV$ or $\int_{V_1}^{V_2} P_{ext}(V) dV$ since the pressures $P_{gas}$ and $P_{ext}$ are equal.
Here is a simple analogy. Consider an applied force pushing a mass (a rigid body) slowly upwards against gravity, where the applied force is only infinitesimally greater than the force of gravity. This is a quasi-static process in mechanics textbooks. The applied force and the force of gravity are equal in magnitude but opposite in direction, so the total force on the mass is zero. The mass has zero acceleration since the net force is zero, there is no total work done on the mass, and there is no change in the kinetic energy of the mass. However, the work done by the applied force $W_{applied}$ is not zero, it is the product of the applied force times the distance the object slowly moves upward. The work done by the applied force here is analogous to the work done by the gas in the gas/piston discussion, and the work done by gravity is analogous to the work done by the external force; each of these forces separately does work on the mass but the net force (zero force) does no work. The change in potential energy $\Delta PE$ is defined as the negative of the work done by gravity, resulting in the standard relationship of elementary mechanics for this example $W_{applied} + \Delta PE = 0$.
For a non quasi-equilibrium process, such as very rapid expansion of the gas, all the gas is not in equilibrium (not in a definite state), and the movement of the piston cannot be ignored. The pressure is non-uniform throughout the gas, the process is irreversible, and the work done by the gas is not $\int_{V_1}^{V_2} P_{gas}(V) dV$ since the gas has no specific state; the work done by the gas on the piston is $\int_{x_1}^{x_2} P_{gassurface}Adx = \int_{V_1}^{V_2} P_{gassurface}dV$ where $P_{gassurface}$ is the average pressure of the gas on the piston surface. The acceleration of the piston is given by $ma \hat i = P_{gassurface}A \hat i + F_{ext} \hat i$ where $a \hat i$ is the acceleration of the piston. For a practical application, $ma \hat i$ of the piston is small, so $P_{gassurface}$ is approximately equal to $|F_{ext}|/A$ in magnitude. $|F_{ext}|/A =P_{ext}$. Therefore, the work done by the gas is approximately $\int_{V_1}^{V_2} P_{ext} dV$ in magnitude. This issue was also addressed by @Chet Miller in his earlier response.