How is a Carnot engine in quasi-equilibrium? If the reversible isothermal expansion and adiabatic expansion both yield positive work (as the pv diagram indicates), it means that the gas inside the cylinder  was compressed before those stages with a pressure higher than the pressure of whatever is on the other side of the piston (e.g. atmospheric pressure). That pressure difference should be infinitesimally small in order to consider the Carnot engine in quasi-equilibrium, but then, how can the gas lose pressure during the isothermal expansion and still have more pressure than whatever is on the other side of the piston in order to keep expanding during the adiabatic expansion phase?
Thank you in advance for your time.
 A: 
how can the gas lose pressure during the isothermal expansion and
still have more pressure than whatever is on the other side of the
piston in order to keep expanding during the adiabatic expansion
phase?

Imagine a vertically oriented piston/cylinder containing an ideal gas with a bag of sand on top of the piston which, in addition to the atmosphere, comprises the external pressure on the gas. The gas is initially in thermal and pressure equilibrium with the surroundings. Now consider the isothermal expansion followed by the adiabatic expansion:
Isothermal expansion:
Now, remove a single grain of sand. This results in the following sequence of events: (1) an infinitesimal reduction in the external pressure below the gas pressure, (2) an infinitesimal increase in the gas volume as the gas does work raising the remaining sand, (3) an infinitesimal decrease in the gas temperature below the surroundings due to the expansion, (4) an infinitesimal transfer of heat from the surroundings to the gas (5) and finally an infinitesimal increase in gas temperature to once again equal the temperature of the surroundings for thermal and pressure equilibrium. Remove the next grain of sand, and repeat.
In the above manner the gas undergoes a series of heat transfers and expansion work such that at each step the temperature is always brought back to equal the constant temperature surroundings, its pressure always brought back to equal the external pressure, and the product of its volume and pressure is always constant.
Adiabatic expansion:
At the end of the isothermal expansion we insulate the piston/cylinder such that there can be no heat exchange with the surroundings.
We again remove a grain of sand. This again results in an infinitesimal decrease in external pressure and an infinitesimal increase in gas volume which does work raising the remaining sand. The gas pressure comes back into equilibrium with the external pressure.
But now, unlike the isothermal expansion, there is no heat transfer to the gas. That means, from the first law, the energy for doing the expansion work come from the internal energy of the gas resulting in a temperature decrease. We continue removing grains of sand, one grain at a time, until the temperature of the gas equals the temperature of the cold reservoir of the surroundings. We can then remove the thermal insulation and begin the isothermal compression process.

I've heard the grains of sand analogy before, but I thought: "wouldn't
removing the grains of sand require us to do some work similar to the
work that the system provides to us with the corresponding expansion,
resulting in no net useful work?"

Actually no. Refer to the figures below. Each grain of sand is slid horizontally on a frictionless surface and brought to rest on an equally horizontal frictionless slot in a platform alongside, as shown in the first figure on the left. The grain of sand begins and ends at rest so there is no change in kinetic energy. Since the displacement if horizontal, there is also no change in gravitational potential energy. So no net work is done.
The only time work is done is when we want to begin to reverse the process as shown on the last figure to the right. The first grain of sand that was removed has to be lifted and placed on the piston to reverse the process. That requires an infinitesimal amount of work.  This illustrates the fact that no real process can be truly reversible, only in the limit. The smaller the grain of sand, the closer it is to ideally reversible.
Hope this helps.

