Provisional results from Sunday's vote showed President Macky Sall's BBY won 82 out of 165 seats, one short of the 83 required for an absolute majority, while the alliance of opposition coalitions Yewwi Askane Wi (YAW) and the Wallu Senegal won 80.
"I salute the Senegalese people ... for the exemplary nature of our democracy and the credibility of our electoral system," Sall said on Twitter after the results were released.
Both BBY and the YAW-Wallu alliance had earlier claimed victory, with opposition leader Ousmane Sonko saying the ruling coalition would try to steal the vote and calling for his supporters to be ready to defend their choice.
BBY secured 125 seats in the last legislative poll in 2017, and the loss of 43 seats reflects growing public acrimony towards Sall, fuelled in part by his refusal to state clearly whether he plans to run for a third mandate in 2024 in breach of term limits.
Frustrations in the usually stable West African country have also been stoked by economic hardship linked to the coronavirus pandemic and rising fuel and food prices.
"The Senegalese people gave a real lesson in democracy to the political class," BBY member Amadou Sall told Reuters.
On Wednesday, YAW, of which Sonko's PASTEF party is a member, said it would not accept the results, citing alleged voting irregularities in northern regions.
A BBY representative said these claims were baseless.
The election commission has not commented on the allegations and YAW says its request to look into the irregularities has been rejected by the commission.
Tensions have run high in the country of 17.5 million since violent protests broke out last year, when Sonko, who came third in the 2019 presidential election, was arrested on rape charges. Sonko denies the allegations. The case against him is still open.