The boat suffered engine failure about three miles (five kilometres) off Manuk beach in Banten province in the morning, Indonesia's search and rescue agency said.
Nine people, including five children, were rescued initially with the help of local fishermen, agency spokesman Mochamad Hernanto told AFP.
The remaining 39 on the stricken vessel at first refused to be picked up by Indonesian rescuers and returned to Java.
But the boat was towed closer to the shore in the evening and all the asylum seekers agreed to be brought ashore, Hernanto said.
Also Read
Morrison said Australian authorities were not involved in the rescue.
Asylum-seekers arriving on unauthorised boats in Australia, often via Indonesia, are a sensitive issue for both sides.
Many have drowned attempting the precarious journey on rickety wooden vessels, and Tony Abbott's conservative government came to power in September on a platform which included turning back boats to Indonesia when it was safe to do so.
But Canberra's military-led Operation Sovereign Borders has raised concerns in Jakarta.
The issue flared up last week when Australia rescued some 60 asylum-seekers from a stricken vessel inside Indonesia's search and rescue zone, and Jakarta refused to take them back.