After the Bugis ousted Tengku Muda, the Malay Yamtuan Muda of Johor, Mahmud Shah III had no choice but to accept Raja Ali's return in 1803. To appease both the Bugis and Tengku Muda, the Sultan married his son, Tengku Hussein, to Tengku Muda's daughter, while his other son, Tengku Abdul Rahman, was made Raja Ali's ward. To maintain his distance from the Bugis, Mahmud Shah III established his capital at Daik, Lingga.[4]