Jamie Dimon, chief executive officer of JPMorgan Chase & Co. Jason Alden | Bloomberg | Getty Images

Somewhere, Jamie Dimon is smiling. J.P. Morgan Chase is close to winning the lead advisory role for the initial public offering of Saudi Aramco, the world's most profitable corporation, edging out rivals for the plum assignment, according to people with knowledge of the situation. A final decision is expected next week and could still change, the people said. Morgan Stanley, which had been jockeying with J.P. Morgan for top billing on the deal, was hurt by its work leading the Uber IPO, according to these people. Saudi officials, who are large owners of Uber through the country's sovereign wealth fund, were displeased with Morgan Stanley after its bankers misjudged demand for the ride-sharing giant's stock in May. The shares tumbled 18% in the first two days of trading and are still well below the IPO price of $45.

The move caps years of efforts by global investment banks to woo the Saudi kingdom for lucrative deals. An IPO of state-owned Saudi Aramco, the world's largest oil company and the Saudi government's main source of revenue, has been the centerpiece of a plan by Crown Prince Mohammad bin Salman to diversify the country away from fossil fuels. With the title of lead advisor comes bragging rights in the high-stakes world of investment banking. Not only is J.P. Morgan in line for the biggest share of fees from a Saudi Aramco IPO, if it pulls off the listing smoothly, it is positioned well for future capital markets assignments from the firm. As lead advisor, J.P. Morgan bankers are privy to the most important discussions involving major decisions with the IPO, and will coordinate the other investment banks on the deal as they distribute shares to their respective institutional clients. Until recently, J.P. Morgan has been viewed as an also-ran behind Morgan Stanley and Goldman Sachs when it comes to advising on IPOs. So it must be particularly sweet to Dimon, the longtime CEO and chairman of J.P. Morgan, that his bank is close to winning the listing. Saudi Aramco produced $111.1 billion in profit last year, more than double what tech giant Apple made.

Second time's the charm

Still, this is the second time that Saudi officials have convened banks for a potential listing, and the on-again, off-again IPO process isn't a lock. An IPO was delayed last year by Mohammad bin Salman, known as MBS, as Saudi Aramco pursued a $69 billion takeover of a Saudi chemical producer. At the time, Saudi officials said that they wanted to raise $100 billion by selling a 5% stake in Saudi Aramco, valuing the company at $2 trillion. That would far outstrip the $25 billion raised in the 2014 IPO of Chinese e-commerce company Alibaba.