In Spanish, the conjunction "al"followed by an infinitive is used in clauses that express either When/while doing [something] or Because of doing [something].
When/while doing something
Alcalentar la leche, me quemé.When I was heating up the milk, I burned myself.
Se ha desmayado alleer la noticia.She fainted while reading the news.
Because of doing something
Al terminar la sesión antes de lo previsto, pudimos volver a casa antes.Because the session finished earlier than expected, we were able to return home earlier.
Al portarse tan mal, lo expulsaron del colegio.Due to his appalling behaviour, he was expelled from school.
Bear in mind that in the second example, where the al + infinitive structure expresses the cause of something happening, al could also be followed by haber + participle, if it is referring to a past action. See El Infinitivo Compuesto.