Mr Mahfouz received 72,356 votes in holding the seat for Labour on a reduced majority with Conservative Henry Higgins receiving 67,495 votes.
The Green Party’s Jess Lee finished third with 22,984 with Liberal Democrat Kuldev Singh Sehra narrowly beating Reform’s Anthony Goodwin by 46 votes, 15,293 to 15,247.
Mahfouz said: “For me this has always been about making sure I engage with the community across Ealing and Hillingdon and I’m delighted they’ve put their faith in me as a representative for the next four years.
“We’ve got a historic third term with Sadiq Khan and we absolutely have to deliver because I’ve seen door after door where people are really hurting across Ealing and Hillingdon, the Tory’s have absolutely obliterated the country in different ways.
“We have an NHS in crisis, a housing service in crisis, cost of living crisis.
“As Labour, we have got solutions, answers and we’re really driving that forward through Sadiq Khan.”
Ealing Central and Acton MP Rupa Huq said: “I think it’s a fantastic result and Bassam Mahfouz will be a fantastic London Assembly member for Ealing and Hillingdon.
“I think Rishi Sunak has to call a general election, the country is running out of patience – 14 years of a Conservative government, nothing seems to be getting better, I think it’s time for a general election.
Higgins said: “Whoever is in City Hall needs to keep him [Sadiq Khan] to account.
“Mahfouz who has won today, must not be in Khan’s shadow and not be star-struck!”
The seat has been in Labour’s hands since 2012 and Mahfouz succeeds former Deputy Chair of the London Assembly Onkar Sahota.
The constituency includes Boris Johnson’s old seat of Uxbridge and South Ruislip.
In the Mayoral election Susan Hall clinched a narrow victory in the area, beating Sadiq Khan with 75,396 to Khan’s 73,257 although Mr Khan won an historic third term overall.