The commandos were called in after the Malaysian tanker MT Bunga Laurel, sent out a distress call late Thursday after pirates armed with AK-47 assault rifles boarded and took control of the ship.
State media said the tanker was headed to Singapore with a cargo of oil worth more than 30 million ringgit (10 million dollars) when it was hijacked.
Malaysian navy chief Admiral Abdul Aziz Jaafar said the commandos, who were manning a commercial vessel protecting shipping in the area, responded to the distress call.
He said one of the navy's Fennec attack helicopters was also involved in rescue, according to the New Straits Times newspaper Saturday, which ran a front page picture of the captured pirates held at gunpoint.
"The attack helicopter kept the pirate's mother ship at bay with several rounds of machine-gun fire while the commandos boarded the tanker," he told the paper.
"The pirates were overpowered after a ... gun battle which saw three of them (pirates) suffering gunshot wounds," Abdul Aziz said.
He said the crew were uninjured as they had locked themselves in a safe room after setting off the ship's security alert system.
Malaysian Prime Minister Najib Razak praised the swift action by the navy.
"We will determine what we should do (with the pirates), whether we are going to bring them here (Malaysia) to be tried or take any other appropriate action," he told the Star daily.
South Korean navy commandos on Friday stormed a ship hijacked by Somali pirates, rescuing all the 21 crew and killing eight pirates.
Piracy has surged off lawless Somalia in recent years, and international warships patrol the area in a bid to clamp down on the problem.
Three Malaysian ships have previously been seized, with the Malaysian International Shipping Corporation, which operates the MT Bunga Laurel, and the Malaysian navy joining forces in 2009 to man a commercial vessel used in escorting and protecting shipping in the area.