LAHORE, Pakistan — Is Imran Khan, a legendary cricket player and international sex symbol, about to become the leader of Pakistan, an Islamic republic with nuclear weapons?

Mr. Khan made a name for himself on the world’s cricket pitches and in London’s nightclubs. But in the two decades since he began striving for higher office in Pakistan, he has undergone a complicated transformation.

He has embraced pious Islam, railing against the United States and distancing himself from his partying days — though his political organization still uses a cricket bat as its symbol. And on Wednesday, when Pakistan holds nationwide elections, Mr. Khan is the party leader widely seen as most likely to emerge with a shot at forming a government.

Mr. Khan enjoys genuine popularity across this country and cordial relations with Pakistan’s domineering military. He has used his celebrity, his charisma and his money to campaign against corruption, one of the most unifying issues in a poor nation that struggles with many dividing lines.