A note on on your last premise: "the Germans were rapidly approaching Moscow". It's a little misleading. In August the advance of Army Group Center (the German concentration advancing on the Moscow axis) effectively stalled after the battle of Smolensk - ostensibly an overwhelming German victory, but not only did enough Red Army forces escape the trap to reform the defensive line, they had enough reserves available to launch a rolling wave of counter-offensives which had the Germans fighting for their lives, particularly around Yel'nya and Roslavl. They weren't going anywhere at that point, Barbarossa had effectively failed its initial aims.
On 3 Aug, AGC's diary records:
"At the beginning of the 7th week of battle the army group stands with partially worn out units, limited munitions supply and without meaningful reserves, in a difficult and costly struggle to achieve the victorious end of the encirclement at Smolensk. The enemy is in number and material greatly superior. On the outer defensive front the bridgehead at Yel'nya is a deeply endangered flashpoint."
I've bolded some text to make my point: in August the Red Army was very much intact, superior in number to the Wehrmacht, and fighting-back with exceptional vigour. There was no immediate threat to Moscow, and thus substantial reserves could be committed to the pressing strategic goal of forestalling any threat to the war effort by Iran flipping for the Axis (whether or not this was a realistic fear, I guess we'll never know - but I suppose they weren't willing to take any chances...). While Germany declared the battle of Smolensk over on 5 Aug, in reality, the defensive battle lasted another month, at least. I guess the rest is history, eh?
I can recommend David Stahel's Operation Barbarossa and Germany's Defeat in the East, for a German perspective, and both volumes of David Glantz's Barbarossa Derailed for a much deeper dive into the subject (which it requires). I'm no expert of the invasion of Iran, but the imperative of securing trade-routes and oil seems rather obvious to me, as ignoble as it was in execution.