Vishvamitra began as King Kaushika of Kanyakubja, a Kshatriya ruler with an army, a treasury, and a lineage going back to Kusha. On a stop at sage Vasishtha's hermitage, he saw the sage's cow Kamadhenu feed his entire army from nothing. He asked for the cow. Vasishtha refused. Kaushika ordered his soldiers to take her by force, and lost his army twice.
That defeat convinced him that a Brahmarishi's power outranked a king's. So he applied a king's method to a sage's problem: escalate, extend the campaign, refuse to stop. Traditional accounts place Mandala 3 of the Rigveda, most of which is credited to him, in the early Vedic family-book period, roughly 1500 to 1000 BCE, though exact dating for the man himself is contested and largely traditional.
What followed was five ranks, and he earned each one only after losing something at the last. Rajarshi first, then Rishi, then Maharshi, then Brahmarishi, granted by Brahma after more than a thousand years of penance in the Himalayas.