A tremendous tzaddik and an astounding talmid chacham, the Ohr Hachaim's holiness enabled him to surpass the laws of nature when necessary.
When the Ohr Hachaim settled in Yerushalayim, Eretz Yisrael was under the control of the Turkish Ottoman Empire.
This was Mahmud I, who inherited the throne in 1730, but spent his first years of rule subduing enemy forces from within and without.
The biography of the Ohr Hachaim describes this sultan as being a strong ruler under whose hand the empire flourished.
It also describes him as being an intellectual who excelled at many different subjects and who also understood astrology, which required excellent math skills.
Indeed, Mahmud I grew up in a kafes ("cage") in Edirne/Adrianople. A kafes was an enclosed area within the harem compound kept under surveillance by palace guards.
Turkish sultans used the kafes to imprison any potential successors to the throne (i.e., their brothers, half-brothers, etc.) rather than executing them (as their predecessors did).
Despite the limitations, Mahmud I used life in the kafes to his advantage. Mahmud I (who was also a hunchback) grew up under the loving influence of his grandmother, and studied with private tutors who taught him a variety of subjects, including literature, history, poetry, and music. He also played chess.
The following story is taken from the Hebrew biography for youth: Toldot Chayav uPa'alav shel Rebbi Chaim Ben-Attar ztzak"l – The Ohr Hachaim Hakadosh by "Aleph" Rosenbaum.
The Quest to Find His Astrological Twin
"Is there another person in the world who shares exactly the same mazal as I?"
Determined to discover whether another was also born on the same day as the sultan at exactly the same time, the sultan continued to search the stars & his astrological charts for an answer.
To his surprise, the sultan discovered that his ben mazal was a Jewish rabbi living in Yerushalayim.
Intrigued to know more about his astrological "twin," the sultan notified his staff that he was leaving the palace for a bit and the Grand Imam would rule in his place.
"I wish to disguise myself as a simple person and survey all the cities of my empire to see with my own eyes how the people are managing. In this way, I can better improve their situation and thus improve the welfare of my kingdom."
He garbed himself as a regular citizen. The only indication of his true status was his jeweled gun, which he kept hidden under the simple clothing.
However, he did not tell a soul where he was going.
What Kind of Mazal is This?
Based on the great reverence with which the Jews referred to the Ohr Hachaim, the disguised sultan expected to see a majestic home with an army of servants.
You can imagine how shocked the sultan was to be led to an old, tiny home located on the edge of a simple courtyard which also hosted the homes of other Jewish families.
The Ohr Hachaim's holy wife answered the door and kindly informed the stranger that her husband was learning Torah with his students, but if the stranger wouldn't mind waiting until noon, he could wait for her husband at the entrance to the courtyard.
Seating himself on the low rock wall surrounding the courtyard, the sultan mused over the fact that he, the great sultan, was sitting on a rock to wait for a rabbi. He also wondered at how a person who shared his successful mazal could be so disadvantaged & impoverished...
However, when a group of Jews approached around noontime, the sultan immediately identified his ben mazal by his tall stature, penetrating eyes, and a holy light emanating from his face.
As the group neared this stranger, who looked like a simple Arab hunchback, the Ohr Hachaim stopped before the stranger and suddenly made the special blessing over a good sovereign, and then said, "Peace upon you, your highness, my king, and welcome to my home!"
The sultan was dumbstruck. How did the Ohr Hachaim know? After all, the sultan hadn't breathed a word to anyone.
When the sultan recovered enough to ask the Ohr Hachaim how he knew, the Ohr Hachaim replied, "Please understand, your majesty, that every king has an angelic representative in Heaven who escorts the king wherever he goes. When I saw the impressive angel standing by your side, I realized you must be a king."
Then the Ohr Hachaim explained that he also made a blessing upon seeing the king, and what that meant.
Now the sultan started to understand that his ben mazal was indeed very special.
But the impoverished circumstances still didn't make sense.
Who is Truly Rich?
"No, no," said the Ohr Hachaim. "I'm happy with my lot, and I'm grateful to the Creator for all the kindness He bestows upon me every day. I have more than I deserve."
The sultan glanced at the poor meal waiting for them on the table.
Yet despite the sultan's norm of feasting on rich royal foods, he found the simple food delicious. And even though the sultan had been quite hungry, he also found the sparse food quite filling.
After the sultan finished his surprisingly satisfying meal, the Ohr Hachaim turned to him and respectfully inquired as to the reason for the sultan's visit.
The sultan described his initial curiosity to discover his ben mazal, and ended by expressing his bemusement at the seemingly pathetic circumstances of his ben mazal (the Ohr Hachaim), whom he expected to be living a life of riches and honor.
"Yet here you are," said the sultan, "living in intolerable conditions."
The Ohr Hachaim smiled as he explained that, on the contrary, he felt richer and happier than all the other wealthy people across the globe.
He then described the life of stress & hassle suffered by many materially successful people, including rulers & princes, noting they often can't even enjoy their luxuries due to their stress & anxiety.
The Ohr Hachaim continued to enumerate the problems suffered by wealthy rulers (war, economy, excruciating decisions, etc.), but when he said, "It could even be that at this very moment, someone from your closest ministers might be planning to betray you or incite the nation against you..."
The sultan opened his mouth to contradict the Ohr Hachaim's suggestion, but then he remembered the excessive delight of some of his ministers in response to the announcement of his plans to vacate his throne for a while.
Instead, he sighed as his newfound concerns grew in his mind and said, "How I wish I could know what's happening in my palace..."
"You can," said the Ohr Hachaim and handed the sultan a small mirror.
The Original Magic Mirror
"Gaze deeply into the mirror," said the Ohr Hachaim. "You'll be able to see whatever you desire."
Now the sultan saw Istanbul, and then his palace.
"Would you like to see what's happening now in your private quarters?" asked the Ohr Hachaim.
"I certainly would!" said the transfixed sultan.
As he continued to gaze into the mirror, he spotted his Grand Imam sitting with his Grand Vizier and plotting how to overthrow the sultan.
The sultan's initial shock turned to rage, and then despair.
"What can I possible do to these scoundrels?" he wailed. "How can I save my kingdom?"
"Do you have any kind of weapon with you?" asked the Ohr Hachaim.
Immediately, the sultan withdrew the jeweled gun hidden beneath his clothes.
"Do not wait another moment," said the Ohr Hachaim. "Take aim — but be careful not to miss!"
The sultan cocked his gun and aimed at the image of the Grand Imam.
The mirror exploded into pieces.
Yet in that split second before it shattered, the sultan managed to see the Grand Imam fall to the floor...lifeless.
The Ohr Hachaim Ensures Good for All
Then the Ohr Hachaim explained that when the sultan would return, he'd be greeted by his "faithful" ministers, who would then tell him that the Grand Imam was murdered by the Jews.
"But you know the truth," said the holy tzaddik. "Nonetheless, do not reveal what really happened. Instead, please keep postponing the judgement against the Jews. After a month, invite all your ministers and servants to a feast, at which point I will appear and reveal the truth before the eyes of the entire nation."
To make an already long story a bit shorter, many people signed a document claiming they personally saw the Jews murder the Grand Imam.
This showed the sultan who was untrustworthy.
In this way, the Ohr Hachaim ensured the continued reign of a friendly & decent ruler while also ensuring the protection of the Jewish community.