Abd Al-Qādir had begun using northeastern Morocco as a refuge and a recruiting base as early as 1840, and French military movements against him heightened border tensions at that time. France made repeated diplomatic demands to Sultan Abd al-Rahman to stop Moroccan support for Abd al-Qādir, but political divisions within the sultanate made this virtually impossible. Tensions were heightened in 1843, when French forces chased a column of Abd al-Qādir supporters deep into Morocco. These men included Alawī tribesmen from Morocco, and French authorities interpreted their actions as a de facto declaration of war. While they did not act immediately, French military authorities threatened to march into the sultanate if support for Abd al-Qādir was not withdrawn, and the border between Algeria and Morocco properly demarcated so that defenses against future incursions could be set up. By early 1844 French troops had constructed a fortification at Lalla-Maghnia, the site of a Muslim shrine near Oujda, and clearly not within territory traditionally claimed by the OttomanRegency of Algiers. An attempt to dislodge these troops peacefully in late May 1844 failed when Alawī tribal fighters fired on the French and were eventually driven back to Oujda. Rumors surrounding this incident fanned the flames of jihad in Morocco. Amid escalating troop buildups and skirmishes in the frontier area, French MarshalThomas Robert Bugeaud insisted that the border be demarcated along the Muluwiya River, a position further west than the Tafna River which Morocco considered to be the border.
The war was formally ended on September 10, 1844 with the signing of the Treaty of Tangiers, in which Morocco agreed to officially recognize Algeria as part of the French Empire., reduce the size of its garrison at Oujda, and establish a commission to demarcate the border. Sultan Abd al-Rahman's agreement to these terms, which amounted to a capitulation to French demands, threw Morocco into chaos, with Alawī and other tribal areas threatening secession in support of Abd al-Qādir, and calls in some circles for al-Rahman to be deposed in favor of Abd al-Qādir. The sultan and his sons eventually regained control over the sultanate, and were able to marginalize Abd al-Qādir's calls for jihad by pointing out that without their support, Abd al-Qādir was not a mujahid, or holy warrior, but merely a mufsid, or rebel. By 1847 the sultan's forces were in jihad against Abd al-Qādir, who surrendered to French forces in December 1847.