Hotly contested race in Christian Metn district goes to Aoun-backed candidate.
Official results showed Camille Khoury, who represented Christian opposition leader Michel Aoun, defeated Gemayel, who was backed by the ruling Western-backed coalition by, by 418 votes.
Gemayel was standing for election in Mount Lebanon’s Metn region, a Christian stronghold north of Beirut.
He had been vying to replace his son Pierre, a Christian cabinet member and politician who was shot dead last November.
Khoury won 39,534 votes as against 39,116 for Gemayel.
Before the final results became clear, both sides in Metn had accused the other side of fraud.
In another by-election on Sunday in west Beirut, Mohammed al-Amin Itani, a candidate of parliament majority leader Saad Hariri’s Future Movement, easily won.
The Hezbollah-led opposition did not officially sponsor a candidate and turnout was just 19 per cent.
Gemayel is expected to stand in next month’s presidential election against Aoun, who has already declared his candidacy.
Under Lebanon’s constitution, the president is traditionally a Maronite Christian who is chosen by parliament.
Gemayel said: “The elections are over. It is time to lick our wounds and strengthen the Christian participation in the power and destiny of the country. Without this, Lebanon cannot survive.
“These elections were effectively a test. They have shown that General Aoun’s support is in broad decline in Christian regions because of the policies he has followed.”
Aoun’s opponents said the strong showing by Gemayel had damaged the opposition leader’s claim to be the strongest Christian political leader.
Aoun’s movement garnered most of the Christian vote in 2005 legislative polls, but his popularity has waned since he forged a shock alliance with the Iran- and Syria-backed Shia Hezbollah movement last year.
Speaking after Sunday’s vote, Aoun said: “They just can’t beat me.”
Antoine Nasrallah, a spokesman for Aoun, told Al Jazeera that one of their supporters was wounded in the hand when he was shot at by Gemayel supporters near the town of Bikfaya.
Gemayel, calling for calm on the streets, said: “We don’t want anyone to drag us into a confrontation that we don’t need.”