It is established in Sruti that whosoever remembers Isvara longingly moments before demise, is certainly attained to Him. Is it the easiest way to attain Moksa without any life-long strive / effort / Adhyatmika pursuits ? Not really. Indeed, it is one of the most difficult ways to attain Moksa.
Every human mind is intensely involved in re-visiting all life-long events / incidents / commissions / omissions moments before demise. All unrealised cherished aspirations emerge on minds surface, permeated with it seeking its gratification in immediate subsequent embodiment of life. This inclination is so strong that even Siddha Yogi-s too, often falter in spite of rigorous life-long Tapasya and infallible determination to be attained to Him. As one grows old, infirmities become more pronounced, failing health becomes yet another hurdle in ones Adhyatmika pursuits, mind becomes more restless, unreined. In that state of mind, is it easy for anyone to remember Isvara few moments before death instead of desperately craving for another lease of life ?
According to Paramhamsa Yogananda, death is merely switching over from one body to another carrying legacy of unredeemed Karma-s, traits and characteristics. It makes profound sense to be initiated into Adhyatmika pursuits at an early age itself so that it becomes ones second nature if not the first. With continuous Adhyatmika pursuits, one is incessantly conscious of His omni-presence and omni-existence mentally prepared to depart with an unruffled inner being. Thus, with entire life transformed / overhauled completely, it is much easier to recollect Him a few moments before demise which otherwise is almost impossible.
Consciousness of Isvara shall always prevail upon the mind of such Mumuksu-s facilitating remembrance of Him a few moments before demise.
There have been several instances mentioned in scriptures to buttress the point. When King of elephants, Gajendra remembered Him, He came rushing to rescue Gajendra from jaws of a demon-alligator. Markandeya remembered Siva when Yama came calling to take him away.
Story involving Ajamila is all the more interesting because he had in reality called out his son, Narayana out of sheer desparation. Since the name belongs to Bhagavana Visnu, He condescended to listen to it and accepted the prayer though Ajamilas was not a pious life hitherto. It is explained that Ajamila had intensely pursued His Bhakti earlier before falling into vices subsequently. That placed him in a good stead in spite of his wayward ways later.
Sanctity of recitation of Isvaras name is so profound that all past evil Karma-s are dissolved, mind introverted and consciousness channelised deeper and deeper into Adhyatma. It is then, much easier to become Ajamila and attain Moksa.