Lok Sabha Secretary General T.K. Vishwanathan, the returning officer for the poll, made the announcement about Ansari's re-election minutes after the counting ended on Tuesday evening at Parliament House.
Ansari polled 490 first preference votes out of 728 valid votes cast in the election. Singh polled 238 votes.
Polling in the vice presidential election was held earlier in the day.
Vishwanathan said that 787 members were eligible to cast vote and 736 exercised their franchise. Eight votes were found invalid.
He said that Ansari needed 365 votes to be declared elected.
"Therefore, Mr. Ansari is duly elected as vice president of India," Vishwanathan announced.
Ansari, who sought re-election for a second term, was backed by the Congress, most other parties of the ruling United Progressive Alliance, those supporting the alliance from outside and some Left parties.
Jaswant Singh, a Bharatiya Janata Party leader and a former minister, had the backing of the National Democratic Alliance (NDA) as well as the AIADMK.
The vice president is elected by members of an electoral college consisting of members of both houses of parliament in accordance with the system of proportional representation by means of single transferable vote. Nominated members of the Rajya Sabha and Lok Sabha are also entitled to take part in the election.