The two political foes stood face-to-face during the short ceremony at the pink-hued Narayanhiti Royal Palace as the king read out the oath and the veteran democracy campaigner repeated it on Sunday, an AFP photographer witnessed.
The oath of office ceremony had been due to take place on Friday at the palace but was postponed because of the premier's ill-health as he recovered from bronchitis.
The 10am (0415 GMT) ceremony on Sunday came hours before Nepal's parliament was due to discuss plans for elections to a new body to frame a new constitution aimed at reducing the monarch's powers in the country.
Koirala is head of the Nepali Congress, one of seven opposition groups which along with Maoist rebels rallied hundreds of thousands of people onto the streets for 19 days this month to protest against Gyanendra's rule.
Police clashed with protesters
who demonstrated for 19 days
Gyanendra seized absolute power in February 2005 after sacking the government, which he accused of corruption and of failing to quell a Maoist insurgency which has left at least 12,500 dead since it started in 1996.
But he was forced to climb down on Monday in the face of protests and recall the parliament that was dissolved in 2002.
He had earlier asked the opposition to name a new premier to lead the country.
Koirala, a veteran democracy campaigner considered the grand old man of Nepali politics who has been premier several times before, was chosen to lead the country into a new era of parliamentary politics.