The former Wales international has been in charge at Millmoor since January, and goes into the final day of the season knowing a win over MK Dons will secure League One survival.
It is a remarkable turnaround, as the Millers were rooted in the bottom four and without a win in 17 games when he replaced Mick Harford.
The Yorkshire side expect to go into voluntary administration after the season ends, meaning they will start next season on -10 points.
A club statement said: "We feel Alan has done a superb job in very difficult circumstances since he took over and we are delighted he has agreed to commit himself for the next two years.
"He is a very dedicated man who puts a lot of energy into his work that has seen us in with a good chance of avoiding relegation despite all the external worries, the squad he has inherited have encountered."