Samaras, leader of the conservative New Democracy party, will head a three-party coalition that includes the socialist PASOK party and the small Democratic Left.
The new government faces massive financial challenges. It must deliver on pledges to implement painful austerity measures, including cutting tens of thousands of civil service jobs, in exchange for billions of euros in rescue loans from other European countries and the International Monetary Fund.
"You are taking over the governance of the country at a difficult and historic moment. You have many battles to fight, both within Greece and abroad," departing caretaker prime minister Panagiotis Pikrammenos told Samaras during the handover.
New Democracy narrowly beat the radical left-wing Syriza party in Sunday's elections, but fell short of the votes needed to form a government on its own, leading to power-sharing talks for three days. Similar talks after an inconclusive May 6 election collapsed after 10 days.
Syriza, led by 37-year-old former student activist Alexis Tsipras, had campaigned on an anti-bailout platform, vowing to pull Greece out of the commitments it made to impose deeply unpopular austerity measures in return for the multibillion-euro bailouts. Greece has been dependent on the bailout since May 2010.
Tapping into widespread anger over austerity, Tsipras quadrupled had his party's support since the 2009 elections and will now be the main opposition party - a role it has already said it will use to oppose the bailout.
"Syriza will fight from the position of responsible, active opposition," spokesman Panos Skourletis said after the coalition agreement was announced.
But with the formation of a largely pro-bailout government, immediate fears of Athens' reneging on its pledges have receded. Combined, the coalition's three parties hold a strong majority of 179 of Parliament's 300 seats - although it is unclear how united they will be. New Democracy and PASOK are longtime foes in a rivalry that dates to the early 1980s.
German Chancellor Angela Merkel, whose country is the main contributor to the bailout, called Samaras to congratulate him and wished him "luck and success in the difficult work that lies ahead of him," the German government said.