هو الذي يسيركم في البر والبحر
He it is Who enables you to travel through land and sea...
which means that He preserves you and maintains you with His care and watching.
حتى إذا كنتم في الفلك وجرين بهم بريح طيبة وفرحوا بها
Till when you are in the ships, and they sail with them with a favorable wind, and they are glad therein...
meaning smoothly and calmly;
جاءتها
then comes (these ships),
ريح عاصف
a stormy wind,
وجاءهم الموج من كل مكان
and the waves come to them from all sides,
وظنوا أنهم أحيط بهم
and they think that they are encircled therein,
meaning that are going to be destroyed.
دعوا الله مخلصين له الدين
Then they invoke Allah, making their faith pure for Him (alone),
meaning that in this situation they would not invoke an idol or statue besides Allah. They would single Him out alone for their supplications and prayers.
This is similar to Allah's statement:
وإذا مسكم الضر فى البحر ضل من تدعون إﻻ إياه فلما نجكم إلى البر أعرضتم وكان اﻻنسن كفورا
And when harm touches you upon the sea, those that you call upon vanish from you except Him (Allah alone). But when He brings you safe to land, you turn away (from Him). And man is ever ungrateful. (17:67)
And in this Surah, He says:
دعوا الله مخلصين له الدين
لين أنجيتنا من هذه
They invoke Allah, making their faith pure for Him (saying): "If You (Allah) deliver us from this (situation).''
لنكونن من الشاكرين
"We shall truly, be of the grateful.''
This means that we will not ascribe others as partners with You. We will later worship You alone as we are praying to You here and now.
Allah states;