The short version is twofold:
the Malaysian and Pakistani troops were incountry as part of the UN operation to attempt to bring peace to wartorn Mogadishu. They were based outside of the city as UN Peacekeepers.
Their appearance at the tail end of Battle of Mogadishu is largely due to the American need for a motorized semi armored force that could potentially help with the extraction of the embattled Task Force Ranger and Delta elements. Prior to Gothic Serpent, President Bill Clinton had rejected Gen Garrison and other's requests for armored elements including Abrams MBTs for firepower and Bradley IFVs for mobility and troop transport as well as additional firepower. POTUS and his adminstration were worried about this armor causing the American "peacekeeping" force to appear as an occupying force, so they rejected armor and instructed Garrison and SOCOM to rely on mobility, helicopters, and the 75th Ranger Rgt's famed firepower for their needs. This had tragic consequences as multiple Humvees and Trucks were destroyed or damaged during the convoy and the extraction, along with that convoy not being capable of the assault firepower needed to get to the two crash sites or break its way out. As the day deteriorated, and TF Ranger became surrounded, Garrison had to call for those elements that were available to him: a motorized element (TF 2-14) of the US Army's 10th Mountain division along with those Pakistani and Malaysian units; the Paks and Malaysians had the armored elements needed: the Paki's had 4 M-48 tanks and the Malaysian element brought German made Condor armored cars. Thus began the "Mogadishu Mile" where the two mile long convoy extracted slowly with some troops running alongside the APCs or Humvees. In the process, the Malaysians suffered one dead, 7 injured and the Pakistani units had 2 injured.
Sources