His enemies all safely dead, Solomon makes an alliance with Pharaoh, the king of Egypt, by marrying his daughter. They live in the city of David while Solomon's palace in Jerusalem is being built.
In those days, the Israelites made their animal sacrifices to God in "high places" (3:2) because they didn't have a permanent temple in which to worship—yet (more on that later).
Now, despite all the Corleone-style executions and stuff, Solomon is actually a very pious guy. He obeys all of God's commandments, and worships him like he should.
He goes to Gibeon, the "great high place" (3:4), to offer 1,000 sacrifices to God.
One night, the Lord appears to him in a dream, and invites him to "Ask what I should give you" (3:4).
Solomon says, "Give your servant […] an understanding mind to govern your people, able to discern between good and evil" (3:9).
The Lord likes that, and gives Solomon "a wise and discerning mind" (or, as the KJV says, "a wise and understanding heart") like nobody's before or after him (3:12).
He also throws in riches, honor, and long life—so long as Solomon obeys his commandments. Why not?
Solomon wakes up a whole lot smarter after that, and returns home to Jerusalem.
As he holds a feast for his servants, two prostitutes come before him seeking his judgment.
One of them (harlot #1) explains that they live together in the same house—just the two of them—and both have recently had babies.
Unfortunately (says harlot #1), harlot #2 accidentally smothered her baby in bed one night. Then she came over while harlot #1 was sleeping with her baby, and she switched her dead baby for harlot #1's living baby.
When harlot #1 woke up, she realized that it was the wrong baby.
But harlot #2 insists that it's a lie, and that the live baby is hers.
They argue in front of Solomon until he observes that it's just one woman's word against the other's. Then he says, "Anybody got a sword? I guess we should just cut the baby in two and give each of you half."
One of the harlots (we're not sure which) is like, "Hmm… Yeah, seems fair."
But the other one says, "Please, my lord, give her the living boy; certainly do not kill him" (3:26).
This lady is obviously going to be a better mom, whether she gave birth to the kid or not, so Solomon declares her the mother and gives her the baby.
This story goes viral in Israel, and everyone in Israel marvels at how royally sagacious Solomon is.