When the loss of power happens just before the gauge shows it's overheating, I think it could be either:

1. The pistons may be starting to seize up
2. The ECU is limiting power (limp mode) to preserve the engine

Things to check:

1. Cooling system - Check the coolant level, radiator fans, water pump, thermostat
2. Engine - Check the oil level, condition and pressure (Yes, engine oil also works to cool the engine)

Is the Check Engine Light (CEL) on?