There were the public falling-outs with his political allies. There was the crushing defeat when he ran for Parliament against the man who became prime minister. More than anything, there was the scorn he earned by quitting last year as New Delhi's top official after just 49 days in office.

Arvind Kejriwal, the former tax official with the chronic cough and the ill-fitting sweaters, the man who had remade himself into a champion for clean government, seemed lost in the political wilderness. The crusading politician was suddenly a punchline.

But on Wednesday, there was Kejriwal on the front page of nearly every Indian newspaper, celebrating election results that again make him New Delhi's chief minister. Kejriwal and the party he created routed the country's best-funded and best-organized political machine and dealt an embarrassing blow to Prime Minister Narendra Modi.

If his election will not rewrite politics in this sprawling nation — Kejriwal's position effectively makes him the New Delhi mayor — it showed that an outsider can win in India's deeply inbred political culture, dominated for decades by two massive parties. It also showed that Modi, whose sweeping election victory last year had seemed to make him unstoppable, and who had invested enormous BJP party resources to back his party's candidate in New Delhi, could actually be beaten.

"Don't get arrogant," Kejriwal told cheering supporters after the results were announced, giving his Aam Admi, or Common Man's Party, 67 of the 70 seats in the New Delhi legislature. The other parties "were defeated because of arrogance and we will meet the same fate if we become arrogant."

Not long ago, Kejriwal's critics accused him of arrogance.

An engineer from a middle-class family who became a bureaucrat in the Indian Revenue Service, Kejriwal quit the tax job in 2006 to become a full-time social activist.

He hit the national spotlight in 2011, when he created an anti-corruption movement and selected an elderly social activist named Anna Hazare as its public face. The avowedly non-political movement quickly caught the imagination of middle-class Indians, angry over years of official corruption and energized by Hazare's public hunger strikes and huge rallies. In barely a year, though, the organization had largely collapsed, in part because of internal infighting and colleagues' accusations that what Kejriwal really wanted was political office.

Soon after, he created the Aam Admi Party, portraying himself as a modern-day Gandhi who would sweep away corruption. He wore his lack of ostentation with pride. He dressed simply, becoming known for his plain sweaters and the scarf he often wrapped around his head to ward off colds. While Indian tax offices are known as places where bureaucrats can get rich, he and his wife (who remains a Revenue Service official) owned little of value beyond an inexpensive Maruti WagonR station wagon.

The Indian media loved Kejriwal, whose protests made great television. Supporters flocked to him. But complications grew when he won his first election to be the New Delhi chief minister in late 2013. He earned fans with his anti-corruption hotline and by lowering rates for electricity and water. But Kejriwal, a man of unrepentant self-righteousness who had spent years as a professional activist, stumbled badly as he tried to navigate the give-and-take of politics. He had little taste for negotiation, and infuriated residents when his protests — which he continued even after taking office — would snarl traffic for hours.

And just 49 days into his tenure, he resigned, angry that lawmakers had blocked his attempt to create a powerful investigative body to root out corruption.

"I will give up the chief minister's office not once but 1,000 times to fight against corruption!" he declared.

But if he thought his resignation would make him a martyr, he was wrong. Instead, he became an object of ridicule, derided by former supporters and political enemies alike.

A few months later, though, something surprising happened.

"Though we had resigned on moral grounds," Kejriwal said in a May statement. "I apologize to the people who wanted the AAP government in Delhi to continue."

It shocked many observers.

"Kejriwal did that rare thing for an Indian politician: he publicly apologized," Mihir Sharma wrote Wednesday in the Business Standard newspaper. "More: he said, persuasively, that he had learned from his mistake."

His apology appeared to have helped kickstart Kejriwal's return to politics. He was also helped by last year's defeat in national elections of the Congress party, India's other main political party, which has found itself adrift since Modi's rise to power. While Congress had controlled New Delhi for much of the last 15 years, it earned not a single seat in the legislature this time.

Kejriwal aimed his campaign squarely at the Congress' core constituency, the poor and working class, playing up his populist credentials as a leader willing to slash electricity and water rates.

The strategy succeeded. He will be sworn in on Saturday, the anniversary of his resignation.

___

Follow Tim Sullivan on Twitter at https://twitter.com/SullivanTimAP