LAHORE, Pakistan — Voters in Pakistan’s second-largest city handed a narrow victory to the governing party on Sunday, according to unofficial results of a bitterly contested by-election seen as a referendum on Nawaz Sharif, who was forced to resign as prime minister by the Supreme Court over corruption charges.

Unofficial results based on news media tallies from all polling stations showed Mr. Sharif’s wife, Kulsoom Nawaz, winning a seat in the National Assembly with a narrow lead of about 15,000 votes over Yasmin Rashid, a gynecologist who ran for the opposition Pakistan Tehreek-e-Insaf party.

Maryam Nawaz Sharif, who ran Mrs. Nawaz’s campaign and is her daughter, said in televised comments to a gathering of supporters late on Sunday night that the results were a victory for her father.

Mrs. Nawaz has been receiving medical treatment in London.

Fewer than half of the 321,786 registered voters came out to vote at 220 polling stations under army supervision in Lahore, the Sharif family’s heartland. The seat fell vacant in July after the Supreme Court ruled that Mr. Sharif was disqualified because of undeclared assets.