The state senate has agreed to the deal, but the state parliament has yet to give its approval.
Hamburg wants to use the company's dividend to offset the cost of the stake increase from 2013.
It said it intends to hold onto the additional stake for a limited period before selling it to a "serious" partner.
Hamburg wants to sell part of its stake to fellow investor Klaus-Michael Kuehne, it said. Mayor Olaf Scholz said Hamburg may sell all of it at a later date.
Hapag-Lloyd shareholder TUI AG is seeking to exit the business and last week sold a 17.4 percent stake in the company to the majority owner, the Albert Ballin consortium, reducing its holding to around 22 percent from nearly 40 percent.
The consortium, which owns 61.6 percent of Hapag-Lloyd, is led by the city state of Hamburg and Kuehne.